├── .gitattributes ├── .gitignore ├── MpqBlockTable.cpp ├── MpqBlockTable.h ├── MpqCrypt.cpp ├── MpqCrypt.h ├── MpqHashTable.cpp ├── MpqHashTable.h ├── SFTypes.h ├── SFUtil.cpp ├── SFUtil.h ├── SFmpq in multi-threaded applications.txt ├── SFmpq_static.cpp ├── SFmpq_static.h ├── SFmpqapi.bas ├── SFmpqapi.cpp ├── SFmpqapi.def ├── SFmpqapi.dsp ├── SFmpqapi.dsw ├── SFmpqapi.h ├── SFmpqapi.odl ├── SFmpqapi.rc ├── SFmpqapi.sln ├── SFmpqapi.vcproj ├── SFmpqapiVB.rtf ├── SFmpqapi_no-lib.cpp ├── SFmpqapi_no-lib.h ├── SFmpqlib.dsp ├── SFmpqlib.vcproj ├── WinError.bas ├── about ├── license.txt ├── linux ├── SFmpqapi.cbp ├── SFmpqapi.workspace ├── poppack.h ├── pshpack1.h ├── windows.cpp └── windows.h └── resource.h /.gitattributes: -------------------------------------------------------------------------------- 1 | *.bas -crlf 2 | *.dsp -crlf 3 | *.dsw -crlf 4 | *.rtf -crlf 5 | *.sln -crlf 6 | *.vcproj -crlf 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *Debug/ 2 | *Release/ 3 | .directory 4 | *.depend 5 | *.layout 6 | *.ncb 7 | *.opt 8 | *.plg 9 | *.suo 10 | *.user 11 | -------------------------------------------------------------------------------- /MpqBlockTable.cpp: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | #include 4 | #include "SFmpqapi.h" 5 | #include "SFUtil.h" 6 | #include "MpqCrypt.h" 7 | 8 | BOOL WriteBlockTable(MPQARCHIVE *mpqOpenArc) 9 | { 10 | DWORD tsz; 11 | 12 | if (mpqOpenArc->MpqHeader.dwBlockTableSize == 0) return TRUE; 13 | if (!mpqOpenArc->lpBlockTable) return FALSE; 14 | 15 | char *buffer = (char *)SFAlloc(sizeof(BLOCKTABLEENTRY) * mpqOpenArc->MpqHeader.dwBlockTableSize); 16 | if (buffer) { 17 | memcpy(buffer,mpqOpenArc->lpBlockTable,sizeof(BLOCKTABLEENTRY) * mpqOpenArc->MpqHeader.dwBlockTableSize); 18 | EncryptData((LPBYTE)buffer,sizeof(BLOCKTABLEENTRY) * mpqOpenArc->MpqHeader.dwBlockTableSize,dwBlockTableKey); 19 | SFSetFilePointer(mpqOpenArc->hFile,mpqOpenArc->dwMPQStart+mpqOpenArc->MpqHeader.dwBlockTableOffset,FILE_BEGIN); 20 | WriteFile(mpqOpenArc->hFile,buffer,sizeof(BLOCKTABLEENTRY) * mpqOpenArc->MpqHeader.dwBlockTableSize,&tsz,0); 21 | SFFree(buffer); 22 | } 23 | else { 24 | EncryptData((LPBYTE)mpqOpenArc->lpBlockTable,sizeof(BLOCKTABLEENTRY) * mpqOpenArc->MpqHeader.dwBlockTableSize,dwBlockTableKey); 25 | SFSetFilePointer(mpqOpenArc->hFile,mpqOpenArc->dwMPQStart+mpqOpenArc->MpqHeader.dwBlockTableOffset,FILE_BEGIN); 26 | WriteFile(mpqOpenArc->hFile,mpqOpenArc->lpBlockTable,sizeof(BLOCKTABLEENTRY) * mpqOpenArc->MpqHeader.dwBlockTableSize,&tsz,0); 27 | DecryptData((LPBYTE)mpqOpenArc->lpBlockTable,sizeof(BLOCKTABLEENTRY) * mpqOpenArc->MpqHeader.dwBlockTableSize,dwBlockTableKey); 28 | } 29 | 30 | return TRUE; 31 | } 32 | -------------------------------------------------------------------------------- /MpqBlockTable.h: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | #ifndef MPQBLOCKTABLE_INCLUDED 4 | #define MPQBLOCKTABLE_INCLUDED 5 | 6 | #include "SFmpqapi.h" 7 | 8 | BOOL WriteBlockTable(MPQARCHIVE *mpqOpenArc); 9 | 10 | #endif // #ifndef MPQBLOCKTABLE_INCLUDED 11 | 12 | -------------------------------------------------------------------------------- /MpqCrypt.cpp: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | #include 4 | #include 5 | #include "MpqCrypt.h" 6 | #include "SFTypes.h" 7 | 8 | bool bCryptTableInit = false; 9 | UInt32 dwCryptTable[0x500]; 10 | UInt32 dwHashTableKey; 11 | UInt32 dwBlockTableKey; 12 | 13 | // The InitCryptTable, HashString, DecryptData, and DetectFileKey are 14 | // based on the versions in StormLib which were written by Ladislav 15 | // Zezula, but may have been modified somewhat by Quantam or ShadowFlare. 16 | bool InitCryptTable() 17 | { 18 | UInt32 seed = 0x00100001; 19 | UInt32 index1 = 0; 20 | UInt32 index2 = 0; 21 | int i; 22 | 23 | if (!bCryptTableInit) 24 | { 25 | for(index1 = 0; index1 < 0x100; index1++) 26 | { 27 | for(index2 = index1, i = 0; i < 5; i++, index2 += 0x100) 28 | { 29 | UInt32 temp1, temp2; 30 | 31 | seed = (seed * 125 + 3) % 0x2AAAAB; 32 | temp1 = (seed & 0xFFFF) << 0x10; 33 | 34 | seed = (seed * 125 + 3) % 0x2AAAAB; 35 | temp2 = (seed & 0xFFFF); 36 | 37 | dwCryptTable[index2] = (temp1 | temp2); 38 | } 39 | } 40 | 41 | bCryptTableInit = true; 42 | } 43 | 44 | return true; 45 | } 46 | 47 | UInt32 HashString(const char *lpszString, UInt32 dwHashType) 48 | { 49 | UInt32 seed1 = 0x7FED7FED; 50 | UInt32 seed2 = 0xEEEEEEEE; 51 | int ch; 52 | 53 | char szNull = 0; 54 | if (!lpszString) 55 | lpszString = &szNull; 56 | 57 | if (dwHashType==HASH_KEY) 58 | while (strchr(lpszString,'\\')!=NULL) lpszString = strchr(lpszString,'\\')+1; 59 | while (*lpszString != 0) 60 | { 61 | ch = toupper(*lpszString++); 62 | 63 | seed1 = dwCryptTable[(dwHashType << 8) + ch] ^ (seed1 + seed2); 64 | seed2 = ch + seed1 + seed2 + (seed2 << 5) + 3; 65 | } 66 | 67 | return seed1; 68 | } 69 | 70 | // The EncryptData function is based on the DecryptData function by 71 | // Ladislav Zezula, but adapted by Quantam to encrypt rather than decrypt. 72 | bool EncryptData(UInt8 *lpbyBuffer, UInt32 dwLength, UInt32 dwKey) 73 | { 74 | UInt32 *lpdwBuffer = (UInt32 *)lpbyBuffer; 75 | UInt32 seed = 0xEEEEEEEE; 76 | UInt32 ch; 77 | 78 | if (!lpbyBuffer) 79 | return false; 80 | 81 | // Round to DWORDs 82 | dwLength >>= 2; 83 | 84 | while(dwLength-- > 0) 85 | 86 | { 87 | seed += dwCryptTable[0x400 + (dwKey & 0xFF)]; 88 | ch = *lpdwBuffer ^ (dwKey + seed); 89 | 90 | dwKey = ((~dwKey << 0x15) + 0x11111111) | (dwKey >> 0x0B); 91 | seed = *lpdwBuffer + seed + (seed << 5) + 3; 92 | 93 | *lpdwBuffer++ = ch; 94 | } 95 | 96 | return true; 97 | } 98 | 99 | bool DecryptData(UInt8 *lpbyBuffer, UInt32 dwLength, UInt32 dwKey) 100 | { 101 | UInt32 *lpdwBuffer = (UInt32 *)lpbyBuffer; 102 | UInt32 seed = 0xEEEEEEEE; 103 | UInt32 ch; 104 | 105 | if (!lpbyBuffer) 106 | return false; 107 | 108 | // Round to DWORDs 109 | dwLength >>= 2; 110 | 111 | while(dwLength-- > 0) 112 | { 113 | seed += dwCryptTable[0x400 + (dwKey & 0xFF)]; 114 | ch = *lpdwBuffer ^ (dwKey + seed); 115 | 116 | dwKey = ((~dwKey << 0x15) + 0x11111111) | (dwKey >> 0x0B); 117 | seed = ch + seed + (seed << 5) + 3; 118 | 119 | *lpdwBuffer++ = ch; 120 | } 121 | 122 | return true; 123 | } 124 | 125 | //----------------------------------------------------------------------------- 126 | // Functions tries to get file decryption key. The trick comes from block 127 | // positions which are stored at the begin of each compressed file. We know the 128 | // file size, that means we know number of blocks that means we know the first 129 | // DWORD value in block position. And if we know encrypted and decrypted value, 130 | // we can find the decryption key !!! 131 | // 132 | // hf - MPQ file handle 133 | // block - DWORD array of block positions 134 | // ch - Decrypted value of the first block pos 135 | 136 | UInt32 DetectFileSeed(UInt32 * block, UInt32 decrypted, UInt32 blocksize) 137 | { 138 | UInt32 saveSeed1; 139 | UInt32 temp = *block ^ decrypted; // temp = seed1 + seed2 140 | // temp = seed1 + stormBuffer[0x400 + (seed1 & 0xFF)] + 0xEEEEEEEE 141 | temp -= 0xEEEEEEEE; // temp = seed1 + stormBuffer[0x400 + (seed1 & 0xFF)] 142 | 143 | 144 | for(int i = 0; i < 0x100; i++) // Try all 256 possibilities 145 | { 146 | UInt32 seed1; 147 | UInt32 seed2 = 0xEEEEEEEE; 148 | UInt32 ch; 149 | 150 | // Try the first DWORD (We exactly know the value) 151 | seed1 = temp - dwCryptTable[0x400 + i]; 152 | seed2 += dwCryptTable[0x400 + (seed1 & 0xFF)]; 153 | ch = block[0] ^ (seed1 + seed2); 154 | 155 | if(ch != decrypted) 156 | continue; 157 | 158 | saveSeed1 = seed1 + 1; 159 | 160 | // If OK, continue and test the second value. We don't know exactly the value, 161 | // but we know that the second one has a value less than or equal to the 162 | // size of the block position table plus the block size 163 | seed1 = ((~seed1 << 0x15) + 0x11111111) | (seed1 >> 0x0B); 164 | seed2 = ch + seed2 + (seed2 << 5) + 3; 165 | 166 | seed2 += dwCryptTable[0x400 + (seed1 & 0xFF)]; 167 | ch = block[1] ^ (seed1 + seed2); 168 | 169 | if(ch <= decrypted + blocksize) 170 | return saveSeed1; 171 | } 172 | return 0; 173 | } 174 | -------------------------------------------------------------------------------- /MpqCrypt.h: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | #ifndef MPQCRYPT_INCLUDED 4 | #define MPQCRYPT_INCLUDED 5 | 6 | #include "SFTypes.h" 7 | 8 | #define HASH_POSITION 0 9 | #define HASH_NAME_A 1 10 | #define HASH_NAME_B 2 11 | #define HASH_KEY 3 12 | 13 | extern UInt32 dwHashTableKey; 14 | extern UInt32 dwBlockTableKey; 15 | 16 | bool InitCryptTable(); 17 | UInt32 HashString(const char *lpszString, UInt32 dwHashType); 18 | bool EncryptData(UInt8 *lpbyBuffer, UInt32 dwLength, UInt32 dwKey); 19 | bool DecryptData(UInt8 *lpbyBuffer, UInt32 dwLength, UInt32 dwKey); 20 | UInt32 DetectFileSeed(UInt32 * block, UInt32 decrypted, UInt32 blocksize); 21 | 22 | #endif // #ifndef MPQCRYPT_INCLUDED 23 | 24 | -------------------------------------------------------------------------------- /MpqHashTable.cpp: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | #include 4 | #include "SFmpqapi.h" 5 | #include "SFUtil.h" 6 | #include "MpqCrypt.h" 7 | 8 | BOOL WriteHashTable(MPQARCHIVE *mpqOpenArc) 9 | { 10 | DWORD tsz; 11 | 12 | char *buffer = (char *)SFAlloc(sizeof(HASHTABLEENTRY) * mpqOpenArc->MpqHeader.dwHashTableSize); 13 | if (buffer) { 14 | memcpy(buffer,mpqOpenArc->lpHashTable,sizeof(HASHTABLEENTRY) * mpqOpenArc->MpqHeader.dwHashTableSize); 15 | EncryptData((LPBYTE)buffer,sizeof(HASHTABLEENTRY) * mpqOpenArc->MpqHeader.dwHashTableSize,dwHashTableKey); 16 | SFSetFilePointer(mpqOpenArc->hFile,mpqOpenArc->dwMPQStart+mpqOpenArc->MpqHeader.dwHashTableOffset,FILE_BEGIN); 17 | WriteFile(mpqOpenArc->hFile,buffer,sizeof(HASHTABLEENTRY) * mpqOpenArc->MpqHeader.dwHashTableSize,&tsz,0); 18 | SFFree(buffer); 19 | } 20 | else { 21 | EncryptData((LPBYTE)mpqOpenArc->lpHashTable,sizeof(HASHTABLEENTRY) * mpqOpenArc->MpqHeader.dwHashTableSize,dwHashTableKey); 22 | SFSetFilePointer(mpqOpenArc->hFile,mpqOpenArc->dwMPQStart+mpqOpenArc->MpqHeader.dwHashTableOffset,FILE_BEGIN); 23 | WriteFile(mpqOpenArc->hFile,mpqOpenArc->lpHashTable,sizeof(HASHTABLEENTRY) * mpqOpenArc->MpqHeader.dwHashTableSize,&tsz,0); 24 | DecryptData((LPBYTE)mpqOpenArc->lpHashTable,sizeof(HASHTABLEENTRY) * mpqOpenArc->MpqHeader.dwHashTableSize,dwHashTableKey); 25 | } 26 | 27 | return TRUE; 28 | } 29 | -------------------------------------------------------------------------------- /MpqHashTable.h: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | #ifndef MPQHASHTABLE_INCLUDED 4 | #define MPQHASHTABLE_INCLUDED 5 | 6 | #include "SFmpqapi.h" 7 | 8 | BOOL WriteHashTable(MPQARCHIVE *mpqOpenArc); 9 | 10 | #endif // #ifndef MPQHASHTABLE_INCLUDED 11 | 12 | -------------------------------------------------------------------------------- /SFTypes.h: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | #ifndef SFTYPES_INCLUDED 4 | #define SFTYPES_INCLUDED 5 | 6 | #if defined(_WIN32) || defined(_WIN64) 7 | 8 | typedef signed char Int8; 9 | typedef signed short Int16; 10 | typedef signed long Int32; 11 | typedef signed __int64 Int64; 12 | 13 | #ifdef _WIN64 14 | typedef signed __int64 IntPtr; 15 | #else 16 | typedef signed int IntPtr; 17 | #endif 18 | 19 | typedef unsigned char UInt8; 20 | typedef unsigned short UInt16; 21 | typedef unsigned long UInt32; 22 | typedef unsigned __int64 UInt64; 23 | 24 | #ifdef _WIN64 25 | typedef unsigned __int64 UIntPtr; 26 | #else 27 | typedef unsigned int UIntPtr; 28 | #endif 29 | 30 | #else 31 | 32 | #include 33 | 34 | typedef int8_t Int8; 35 | typedef int16_t Int16; 36 | typedef int32_t Int32; 37 | typedef int64_t Int64; 38 | typedef intptr_t IntPtr; 39 | 40 | typedef uint8_t UInt8; 41 | typedef uint16_t UInt16; 42 | typedef uint32_t UInt32; 43 | typedef uint64_t UInt64; 44 | typedef uintptr_t UIntPtr; 45 | 46 | #endif 47 | 48 | union IntConv { 49 | Int8 i8[8]; 50 | UInt8 ui8[8]; 51 | Int16 i16[4]; 52 | UInt16 ui16[4]; 53 | Int32 i32[2]; 54 | UInt32 ui32[2]; 55 | Int64 i64; 56 | UInt64 ui64; 57 | }; 58 | 59 | #endif // #ifndef SFTYPES_INCLUDED 60 | 61 | -------------------------------------------------------------------------------- /SFUtil.cpp: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | #include 4 | #include 5 | #include "SFTypes.h" 6 | 7 | void WINAPI SFMemZero(LPVOID lpvDestination, DWORD dwLength) 8 | { 9 | DWORD dwPrevLen = dwLength; 10 | LPDWORD lpdwDestination = (LPDWORD)lpvDestination; 11 | LPBYTE lpbyDestination; 12 | 13 | dwLength >>= 2; 14 | 15 | while (dwLength--) 16 | *lpdwDestination++ = 0; 17 | 18 | lpbyDestination = (LPBYTE)lpdwDestination; 19 | 20 | dwLength = dwPrevLen; 21 | dwLength &= 3; 22 | 23 | while (dwLength--) 24 | *lpbyDestination++ = 0; 25 | } 26 | 27 | LPVOID WINAPI SFAlloc(DWORD dwSize) 28 | { 29 | LPVOID lpMemory = malloc(dwSize); 30 | if (lpMemory) SFMemZero(lpMemory,dwSize); 31 | return lpMemory; 32 | } 33 | 34 | void WINAPI SFFree(LPVOID lpvMemory) 35 | { 36 | if (lpvMemory) free(lpvMemory); 37 | } 38 | 39 | Int64 SFGetFileSize(HANDLE hFile) 40 | { 41 | IntConv FileSize; 42 | 43 | FileSize.ui64 = 0; 44 | 45 | FileSize.ui32[0] = ::GetFileSize(hFile, &FileSize.ui32[1]); 46 | 47 | if (FileSize.ui32[0] == INVALID_FILE_SIZE) { 48 | if (::GetLastError() != NO_ERROR) 49 | return -1; 50 | } 51 | 52 | return FileSize.i64; 53 | } 54 | 55 | Int64 SFSetFilePointer(HANDLE hFile, Int64 nDistance, UInt32 dwMoveMethod) 56 | { 57 | IntConv FilePos; 58 | 59 | FilePos.i64 = nDistance; 60 | 61 | FilePos.i32[0] = ::SetFilePointer(hFile, FilePos.i32[0], &FilePos.i32[1], dwMoveMethod); 62 | 63 | #ifdef INVALID_SET_FILE_POINTER 64 | if (FilePos.ui32[0] == INVALID_SET_FILE_POINTER) { 65 | #else 66 | if (FilePos.ui32[0] == INVALID_FILE_SIZE) { 67 | #endif 68 | if (::GetLastError() != NO_ERROR) 69 | return -1; 70 | } 71 | 72 | return FilePos.i64; 73 | } 74 | 75 | size_t strlnlen(const char *strline) 76 | { 77 | if (strline==0) return 0; 78 | const char *strcr = strchr(strline,'\r'); 79 | const char *strlf = strchr(strline,'\n'); 80 | if (strcr==0 && strlf==0) return strlen(strline); 81 | if (strcr!=0 && (strcr 7 | #include "SFTypes.h" 8 | 9 | LPVOID WINAPI SFAlloc(DWORD dwSize); 10 | void WINAPI SFFree(LPVOID lpvMemory); 11 | void WINAPI SFMemZero(LPVOID lpvDestination, DWORD dwLength); 12 | Int64 SFGetFileSize(HANDLE hFile); 13 | Int64 SFSetFilePointer(HANDLE hFile, Int64 nDistance, UInt32 dwMoveMethod); 14 | size_t strlnlen(const char *strline); 15 | char *nextline(const char *strline); 16 | 17 | #endif // #ifndef SFUTIL_INCLUDED 18 | 19 | -------------------------------------------------------------------------------- /SFmpq in multi-threaded applications.txt: -------------------------------------------------------------------------------- 1 | ==================================== 2 | SFmpq in multi-threaded applications 3 | ==================================== 4 | 5 | A note about archive and file handles: In most cases, archive and file handles should not be shared between threads. Instead, open a new handle for each thread that will be reading from or writing to the archive or file. However, if no threads have direct access to the handle and only one is able to use the archive or file at a time, sharing handles can be done. Also, archive handles may be shared between threads when you are only reading files from the archive. 6 | 7 | ------------------------------- 8 | Always nonthread-safe functions 9 | ------------------------------- 10 | SFileOpenFileAsArchive 11 | SFileOpenArchive 12 | SFileCloseArchive 13 | SFileOpenFile 14 | SFileOpenFileEx 15 | SFileCloseFile 16 | SFileSetLocale (same value is used for all threads, so changing it for one changes it for all) 17 | SFileSetBasePath (should not be called at same time as itself or SFileGetBasePath, same value is used for all threads) 18 | SFileSetArchivePriority 19 | MpqOpenArchiveForUpdate 20 | MpqCloseUpdatedArchive 21 | MpqAddFileToArchiveEx 22 | MpqAddFileToArchive 23 | MpqAddWaveToArchive 24 | MpqAddFileFromBufferEx 25 | MpqAddFileFromBuffer 26 | MpqAddWaveFromBuffer 27 | MpqRenameFile 28 | MpqRenameAndSetFileLocale 29 | MpqDeleteFile 30 | MpqDeleteFileWithLocale 31 | MpqCompactArchive 32 | MpqSetFileLocale 33 | 34 | ----------------------------------- 35 | Conditionally thread-safe functions 36 | ----------------------------------- 37 | 38 | Note: All file reading functions are thread-safe if separate handles are used for each thread and no functions are being used that would change the archive or files in any way. If an archive is opened with write access, no other thread should be able to open another handle to it. 39 | 40 | Should not be called while opening or closing archives or files 41 | --------------------------------------------------------------- 42 | SFileGetArchiveName 43 | SFileGetFileName 44 | SFileGetFileInfo 45 | 46 | Should not be called if the archive or file handle being used will be closed 47 | ---------------------------------------------------------------------------- 48 | SFileGetFileSize 49 | SFileGetFileArchive 50 | SFileSetFilePointer 51 | SFileReadFile 52 | SFileListFiles 53 | SFileFindMpqHeader 54 | 55 | Other conditions 56 | ---------------- 57 | SFileGetBasePath (should not be called at same time as SFileSetBasePath) 58 | 59 | ---------------------------- 60 | Always thread-safe functions 61 | ---------------------------- 62 | SFileDestroy 63 | StormDestroy 64 | SFMpqDestroy 65 | MpqInitialize 66 | MpqGetVersionString 67 | MpqGetVersion 68 | SFMpqGetVersionString 69 | SFMpqGetVersionString2 70 | SFMpqGetVersion 71 | AboutSFMpq 72 | SFMpqCompareVersion 73 | 74 | -------------------------------------------------------------------------------- /SFmpq_static.cpp: -------------------------------------------------------------------------------- 1 | /* License information for this code is in license.txt */ 2 | 3 | #include "..\\SFmpqapi\\SFmpq_static.h" 4 | 5 | void LoadSFMpq() 6 | { 7 | } 8 | 9 | void FreeSFMpq() 10 | { 11 | } 12 | 13 | -------------------------------------------------------------------------------- /SFmpq_static.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ShadowFlare MPQ Static Library. (c) ShadowFlare Software 2002-2010 4 | License information for this code is in license.txt 5 | 6 | */ 7 | 8 | #ifndef SHADOWFLARE_MPQ_LIB_INCLUDED 9 | #define SHADOWFLARE_MPQ_LIB_INCLUDED 10 | 11 | #ifndef SFMPQ_STATIC 12 | #define SFMPQ_STATIC 13 | #endif 14 | 15 | #include "SFmpqapi.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | // These no longer need to be called. They are only provided for 22 | // compatibility with older versions of this static library 23 | void LoadSFMpq(); 24 | void FreeSFMpq(); 25 | 26 | #ifdef __cplusplus 27 | }; // extern "C" 28 | #endif 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /SFmpqapi.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "SFmpqapi" 2 | Option Explicit 3 | 4 | ' ShadowFlare MPQ API Library. (c) ShadowFlare Software 2002-2010 5 | ' License information for this code is in license.txt and 6 | ' included in this file at the end of this comment. 7 | 8 | ' All functions below are actual functions that are part of this 9 | ' library and do not need any additional dll files. It does not 10 | ' even require Storm to be able to decompress or compress files. 11 | 12 | ' This library emulates the interface of Lmpqapi and Storm MPQ 13 | ' functions, so it may be used as a replacement for them in 14 | ' MPQ extractors/archivers without even needing to recompile 15 | ' the program that uses Lmpqapi or Storm. It has a few features 16 | ' not included in Lmpqapi and Storm, such as extra flags for some 17 | ' functions, setting the locale ID of existing files, and adding 18 | ' files without having to write them somewhere else first. Also, 19 | ' MPQ handles used by functions prefixed with "SFile" and "Mpq" 20 | ' can be used interchangably; all functions use the same type 21 | ' of MPQ handles. You cannot, however, use handles from this 22 | ' library with storm or lmpqapi or vice-versa. Doing so will 23 | ' most likely result in a crash. 24 | 25 | ' Revision History: 26 | ' (Release date) 1.08 (ShadowFlare) 27 | ' - Fixed a buffer overflow that would occur when reading files 28 | ' if neither using a buffer that is large enough to contain the 29 | ' entire file nor has a size that is a multiple of 4096 30 | ' - Added SFileOpenFileAsArchive which opens an archive that is 31 | ' contained within an already open archive 32 | ' - Added MpqRenameAndSetFileLocale and MpqDeleteFileWithLocale. 33 | ' These have extra parameters that allow you to use them with 34 | ' files having language codes other than what was last set 35 | ' using SFileSetLocale 36 | ' - Fixed a bug that caused (listfile) to get cleared if adding 37 | ' files with a locale ID other than 0 38 | ' - Added MpqOpenArchiveForUpdateEx which allows creating 39 | ' archives with different block sizes 40 | ' - SFileListFiles can list the contents of bncache.dat without 41 | ' needing an external list 42 | 43 | ' 06/12/2002 1.07 (ShadowFlare) 44 | ' - No longer requires Storm.dll to compress or decompress 45 | ' Warcraft III files 46 | ' - Added SFileListFiles for getting names and information 47 | ' about all of the files in an archive 48 | ' - Fixed a bug with renaming and deleting files 49 | ' - Fixed a bug with adding wave compressed files with 50 | ' low compression setting 51 | ' - Added a check in MpqOpenArchiveForUpdate for proper 52 | ' dwMaximumFilesInArchive values (should be a number that 53 | ' is a power of 2). If it is not a proper value, it will 54 | ' be rounded up to the next higher power of 2 55 | 56 | ' 05/09/2002 1.06 (ShadowFlare) 57 | ' - Compresses files without Storm.dll! 58 | ' - If Warcraft III is installed, this library will be able to 59 | ' find Storm.dll on its own. (Storm.dll is needed to 60 | ' decompress Warcraft III files) 61 | ' - Fixed a bug where an embedded archive and the file that 62 | ' contains it would be corrupted if the archive was modified 63 | ' - Able to open all .w3m maps now 64 | 65 | ' 29/06/2002 1.05 (ShadowFlare) 66 | ' - Supports decompressing files from Warcraft III MPQ archives 67 | ' if using Storm.dll from Warcraft III 68 | ' - Added MpqAddFileToArchiveEx and MpqAddFileFromBufferEx for 69 | ' using extra compression types 70 | 71 | ' 29/05/2002 1.04 (ShadowFlare) 72 | ' - Files can be compressed now! 73 | ' - Fixed a bug in SFileReadFile when reading data not aligned 74 | ' to the block size 75 | ' - Optimized some of SFileReadFile's code. It can read files 76 | ' faster now 77 | ' - SFile functions may now be used to access files not in mpq 78 | ' archives as you can with the real storm functions 79 | ' - MpqCompactArchive will no longer corrupt files with the 80 | ' MODCRYPTKEY flag as long as the file is either compressed, 81 | ' listed in "(listfile)", is "(listfile)", or is located in 82 | ' the same place in the compacted archive; so it is safe 83 | ' enough to use it on almost any archive 84 | ' - Added MpqAddWaveFromBuffer 85 | ' - Better handling of archives with no files 86 | ' - Fixed compression with COMPRESS2 flag 87 | 88 | ' 15/05/2002 1.03 (ShadowFlare) 89 | ' - Supports adding files with the compression attribute (does 90 | ' not actually compress files). Now archives created with 91 | ' this dll can have files added to them through lmpqapi 92 | ' without causing staredit to crash 93 | ' - SFileGetBasePath and SFileSetBasePath work more like their 94 | ' Storm equivalents now 95 | ' - Implemented MpqCompactArchive, but it is not finished yet. 96 | ' In its current state, I would recommend against using it 97 | ' on archives that contain files with the MODCRYPTKEY flag, 98 | ' since it will corrupt any files with that flag 99 | ' - Added SFMpqGetVersionString2 which may be used in Visual 100 | ' Basic to get the version string 101 | 102 | ' 07/05/2002 1.02 (ShadowFlare) 103 | ' - SFileReadFile no longer passes the lpOverlapped parameter it 104 | ' receives to ReadFile. This is what was causing the function 105 | ' to fail when used in Visual Basic 106 | ' - Added support for more Storm MPQ functions 107 | ' - GetLastError may now be used to get information about why a 108 | ' function failed 109 | 110 | ' 01/05/2002 1.01 (ShadowFlare) 111 | ' - Added ordinals for Storm MPQ functions 112 | ' - Fixed MPQ searching functionality of SFileOpenFileEx 113 | ' - Added a check for whether a valid handle is given when 114 | ' SFileCloseArchive is called 115 | ' - Fixed functionality of SFileSetArchivePriority when multiple 116 | ' files are open 117 | ' - File renaming works for all filenames now 118 | ' - SFileReadFile no longer reallocates the buffer for each block 119 | ' that is decompressed. This should make SFileReadFile at least 120 | ' a little faster 121 | 122 | ' 30/04/2002 1.00 (ShadowFlare) 123 | ' - First version. 124 | ' - Compression not yet supported 125 | ' - Does not use SetLastError yet, so GetLastError will not return any 126 | ' errors that have to do with this library 127 | ' - MpqCompactArchive not implemented 128 | 129 | ' Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare) 130 | 131 | ' License information: 132 | 133 | ' Copyright (c) 2002-2010, ShadowFlare 134 | ' All rights reserved. 135 | 136 | ' Redistribution and use in source and binary forms, with or without 137 | ' modification, are permitted provided that the following conditions 138 | ' are met: 139 | 140 | ' 1. Redistributions of source code must retain the above copyright 141 | ' notice, this list of conditions and the following disclaimer. 142 | ' 2. Redistributions in binary form must reproduce the above copyright 143 | ' notice, this list of conditions and the following disclaimer in the 144 | ' documentation and/or other materials provided with the distribution. 145 | 146 | ' THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND 147 | ' ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 148 | ' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 149 | ' ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 150 | ' FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 151 | ' DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 152 | ' OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 153 | ' HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 154 | ' LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 155 | ' OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 156 | ' SUCH DAMAGE. 157 | 158 | Type SFMPQVERSION 159 | Major As Integer 160 | Minor As Integer 161 | Revision As Integer 162 | Subrevision As Integer 163 | End Type 164 | 165 | ' MpqInitialize does nothing. It is only provided for 166 | ' compatibility with MPQ archivers that use lmpqapi. 167 | Declare Function MpqInitialize Lib "SFmpq.dll" () As Boolean 168 | 169 | Declare Function MpqGetVersionString Lib "SFmpq.dll" () As String 170 | Declare Function MpqGetVersion Lib "SFmpq.dll" () As Single 171 | 172 | Declare Sub SFMpqDestroy Lib "SFmpq.dll" () ' This no longer needs to be called. It is only provided for compatibility with older versions 173 | 174 | Declare Sub AboutSFMpq Lib "SFmpq.dll" () ' Displays an about page in a web browser (this has only been tested in Internet Explorer). This is only for the dll version of SFmpq 175 | 176 | ' SFMpqGetVersionString2's return value is the required length of the buffer plus 177 | ' the terminating null, so use SFMpqGetVersionString2(ByVal 0&, 0) to get the length. 178 | Declare Function SFMpqGetVersionString Lib "SFmpq.dll" () As String 179 | Declare Function SFMpqGetVersionString2 Lib "SFmpq.dll" (ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Long 180 | Declare Function SFMpqGetVersion Lib "SFmpq.dll" () As SFMPQVERSION 181 | 182 | ' General error codes 183 | Public Const MPQ_ERROR_MPQ_INVALID As Long = &H85200065 184 | Public Const MPQ_ERROR_FILE_NOT_FOUND As Long = &H85200066 185 | Public Const MPQ_ERROR_DISK_FULL As Long = &H85200068 'Physical write file to MPQ failed. Not sure of exact meaning 186 | Public Const MPQ_ERROR_HASH_TABLE_FULL As Long = &H85200069 187 | Public Const MPQ_ERROR_ALREADY_EXISTS As Long = &H8520006A 188 | Public Const MPQ_ERROR_BAD_OPEN_MODE As Long = &H8520006C 'When MOAU_READ_ONLY is used without MOAU_OPEN_EXISTING 189 | 190 | Public Const MPQ_ERROR_COMPACT_ERROR As Long = &H85300001 191 | 192 | ' MpqOpenArchiveForUpdate flags 193 | Public Const MOAU_CREATE_NEW As Long = &H0 194 | Public Const MOAU_CREATE_ALWAYS As Long = &H8 'Was wrongly named MOAU_CREATE_NEW 195 | Public Const MOAU_OPEN_EXISTING As Long = &H4 196 | Public Const MOAU_OPEN_ALWAYS As Long = &H20 197 | Public Const MOAU_READ_ONLY As Long = &H10 'Must be used with MOAU_OPEN_EXISTING 198 | Public Const MOAU_MAINTAIN_ATTRIBUTES As Long = &H2 'Will be used in a future version to create the (attributes) file 199 | Public Const MOAU_MAINTAIN_LISTFILE As Long = &H1 200 | 201 | ' MpqOpenArchiveForUpdateEx constants 202 | Public Const DEFAULT_BLOCK_SIZE As Long = 3 ' 512 << number = block size 203 | Public Const USE_DEFAULT_BLOCK_SIZE As Long = &HFFFF ' Use default block size that is defined internally 204 | 205 | ' MpqAddFileToArchive flags 206 | Public Const MAFA_EXISTS As Long = &H80000000 'Will be added if not present 207 | Public Const MAFA_UNKNOWN40000000 As Long = &H40000000 208 | Public Const MAFA_MODCRYPTKEY As Long = &H20000 209 | Public Const MAFA_ENCRYPT As Long = &H10000 210 | Public Const MAFA_COMPRESS As Long = &H200 211 | Public Const MAFA_COMPRESS2 As Long = &H100 212 | Public Const MAFA_REPLACE_EXISTING As Long = &H1 213 | 214 | ' MpqAddFileToArchiveEx compression flags 215 | Public Const MAFA_COMPRESS_STANDARD As Long = &H8 'Standard PKWare DCL compression 216 | Public Const MAFA_COMPRESS_DEFLATE As Long = &H2 'ZLib's deflate compression 217 | Public Const MAFA_COMPRESS_BZIP2 As Long = &H10 'bzip2 compression 218 | Public Const MAFA_COMPRESS_WAVE As Long = &H81 'Stereo wave compression 219 | Public Const MAFA_COMPRESS_WAVE2 As Long = &H41 'Mono wave compression 220 | 221 | ' Flags for individual compression types used for wave compression 222 | Public Const MAFA_COMPRESS_WAVECOMP1 As Long = &H80 'Main compressor for stereo wave compression 223 | Public Const MAFA_COMPRESS_WAVECOMP2 As Long = &H40 'Main compressor for mono wave compression 224 | Public Const MAFA_COMPRESS_WAVECOMP3 As Long = &H1 'Secondary compressor for wave compression 225 | 226 | ' ZLib deflate compression level constants (used with MpqAddFileToArchiveEx and MpqAddFileFromBufferEx) 227 | Public Const Z_NO_COMPRESSION As Long = 0 228 | Public Const Z_BEST_SPEED As Long = 1 229 | Public Const Z_BEST_COMPRESSION As Long = 9 230 | Public Const Z_DEFAULT_COMPRESSION As Long = (-1) 231 | 232 | ' MpqAddWAVToArchive quality flags 233 | Public Const MAWA_QUALITY_HIGH As Long = 1 234 | Public Const MAWA_QUALITY_MEDIUM As Long = 0 235 | Public Const MAWA_QUALITY_LOW As Long = 2 236 | 237 | ' SFileGetFileInfo flags 238 | Public Const SFILE_INFO_BLOCK_SIZE As Long = &H1 'Block size in MPQ 239 | Public Const SFILE_INFO_HASH_TABLE_SIZE As Long = &H2 'Hash table size in MPQ 240 | Public Const SFILE_INFO_NUM_FILES As Long = &H3 'Number of files in MPQ 241 | Public Const SFILE_INFO_TYPE As Long = &H4 'Is Long a file or an MPQ? 242 | Public Const SFILE_INFO_SIZE As Long = &H5 'Size of MPQ or uncompressed file 243 | Public Const SFILE_INFO_COMPRESSED_SIZE As Long = &H6 'Size of compressed file 244 | Public Const SFILE_INFO_FLAGS As Long = &H7 'File flags (compressed, etc.), file attributes if a file not in an archive 245 | Public Const SFILE_INFO_PARENT As Long = &H8 'Handle of MPQ that file is in 246 | Public Const SFILE_INFO_POSITION As Long = &H9 'Position of file pointer in files 247 | Public Const SFILE_INFO_LOCALEID As Long = &HA 'Locale ID of file in MPQ 248 | Public Const SFILE_INFO_PRIORITY As Long = &HB 'Priority of open MPQ 249 | Public Const SFILE_INFO_HASH_INDEX As Long = &HC 'Hash index of file in MPQ 250 | Public Const SFILE_INFO_BLOCK_INDEX As Long = &HD 'Block table index of file in MPQ 251 | 252 | ' Return values of SFileGetFileInfo when SFILE_INFO_TYPE flag is used 253 | Public Const SFILE_TYPE_MPQ As Long = &H1 254 | Public Const SFILE_TYPE_FILE As Long = &H2 255 | 256 | ' SFileListFiles flags 257 | Public Const SFILE_LIST_MEMORY_LIST As Long = &H1 ' Specifies that lpFilelists is a file list from memory, rather than being a list of file lists 258 | Public Const SFILE_LIST_ONLY_KNOWN As Long = &H2 ' Only list files that the function finds a name for 259 | Public Const SFILE_LIST_ONLY_UNKNOWN As Long = &H4 ' Only list files that the function does not find a name for 260 | Public Const SFILE_LIST_FLAG_UNKNOWN As Long = &H8 ' Use without SFILE_LIST_ONLY_KNOWN or SFILE_LIST_FLAG_UNKNOWN to list all files, but will set dwFileExists to 3 if file's name is not found 261 | 262 | Public Const INVALID_HANDLE_VALUE As Long = -1 263 | 264 | Public Const FILE_BEGIN As Long = 0 265 | Public Const FILE_CURRENT As Long = 1 266 | Public Const FILE_END As Long = 2 267 | 268 | ' SFileOpenArchive flags 269 | Public Const SFILE_OPEN_HARD_DISK_FILE As Long = &H0 'Open archive without regard to the drive type it resides on 270 | Public Const SFILE_OPEN_CD_ROM_FILE As Long = &H1 'Open the archive only if it is on a CD-ROM 271 | Public Const SFILE_OPEN_ALLOW_WRITE As Long = &H8000 'Open file with write access 272 | 273 | ' SFileOpenFileEx search scopes 274 | Public Const SFILE_SEARCH_CURRENT_ONLY As Long = &H0 'Used with SFileOpenFileEx; only the archive with the handle specified will be searched for the file 275 | Public Const SFILE_SEARCH_ALL_OPEN As Long = &H1 'SFileOpenFileEx will look through all open archives for the file 276 | 277 | Type FILELISTENTRY 278 | dwFileExists As Long ' Nonzero if this entry is used 279 | lcLocale As Long ' Locale ID of file 280 | dwCompressedSize As Long ' Compressed size of file 281 | dwFullSize As Long ' Uncompressed size of file 282 | dwFlags As Long ' Flags for file 283 | szFileName(259) As Byte 284 | End Type 285 | 286 | ' Storm functions implemented by this library 287 | Declare Function SFileOpenArchive Lib "SFmpq.dll" (ByVal lpFileName As String, ByVal dwPriority As Long, ByVal dwFlags As Long, ByRef hMPQ As Long) As Boolean 288 | Declare Function SFileCloseArchive Lib "SFmpq.dll" (ByVal hMPQ As Long) As Boolean 289 | Declare Function SFileOpenFileAsArchive Lib "SFmpq.dll" (ByVal hSourceMPQ As Long, ByVal lpFileName As String, ByVal dwPriority As Long, ByVal dwFlags As Long, ByRef hMPQ As Long) As Boolean 290 | Declare Function SFileGetArchiveName Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean 291 | Declare Function SFileOpenFile Lib "SFmpq.dll" (ByVal lpFileName As String, ByRef hFile As Long) As Boolean 292 | Declare Function SFileOpenFileEx Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String, ByVal dwSearchScope As Long, ByRef hFile As Long) As Boolean 293 | Declare Function SFileCloseFile Lib "SFmpq.dll" (ByVal hFile As Long) As Boolean 294 | Declare Function SFileGetFileSize Lib "SFmpq.dll" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long 295 | Declare Function SFileGetFileArchive Lib "SFmpq.dll" (ByVal hFile As Long, ByRef hMPQ As Long) As Boolean 296 | Declare Function SFileGetFileName Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean 297 | Declare Function SFileSetFilePointer Lib "SFmpq.dll" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lplDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long 298 | Declare Function SFileReadFile Lib "SFmpq.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByRef lpOverlapped As Any) As Boolean 299 | Declare Function SFileSetLocale Lib "SFmpq.dll" (ByVal nNewLocale As Long) As Long 300 | Declare Function SFileGetBasePath Lib "SFmpq.dll" (ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean 301 | Declare Function SFileSetBasePath Lib "SFmpq.dll" (ByVal lpNewBasePath As String) As Boolean 302 | 303 | ' Extra storm-related functions 304 | Declare Function SFileGetFileInfo Lib "SFmpq.dll" (ByVal hFile As Long, ByVal dwInfoType As Long) As Long 305 | Declare Function SFileSetArchivePriority Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal dwPriority As Long) As Boolean 306 | Declare Function SFileFindMpqHeader Lib "SFmpq.dll" (ByVal hFile As Long) As Long 307 | Declare Function SFileListFiles Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileLists As String, ByRef lpListBuffer As FILELISTENTRY, ByVal dwFlags As Long) As Boolean 308 | 309 | ' Archive editing functions implemented by this library 310 | Declare Function MpqOpenArchiveForUpdate Lib "SFmpq.dll" (ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwMaximumFilesInArchive As Long) As Long 311 | Declare Function MpqCloseUpdatedArchive Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal dwUnknown2 As Long) As Long 312 | Declare Function MpqAddFileToArchive Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpSourceFileName As String, ByVal lpDestFileName As String, ByVal dwFlags As Long) As Boolean 313 | Declare Function MpqAddWaveToArchive Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpSourceFileName As String, ByVal lpDestFileName As String, ByVal dwFlags As Long, ByVal dwQuality As Long) As Boolean 314 | Declare Function MpqRenameFile Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpcOldFileName As String, ByVal lpcNewFileName As String) As Boolean 315 | Declare Function MpqDeleteFile Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String) As Boolean 316 | Declare Function MpqCompactArchive Lib "SFmpq.dll" (ByVal hMPQ As Long) As Boolean 317 | 318 | ' Extra archive editing functions 319 | Declare Function MpqOpenArchiveForUpdateEx Lib "SFmpq.dll" (ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwMaximumFilesInArchive As Long, ByVal dwBlockSize As Long) As Long 320 | Declare Function MpqAddFileToArchiveEx Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpSourceFileName As String, ByVal lpDestFileName As String, ByVal dwFlags As Long, ByVal dwCompressionType As Long, ByVal dwCompressLevel As Long) As Boolean 321 | Declare Function MpqAddFileFromBufferEx Lib "SFmpq.dll" (ByVal hMPQ As Long, ByRef lpBuffer As Any, ByVal dwLength As Long, ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwCompressionType As Long, ByVal dwCompressLevel As Long) As Boolean 322 | Declare Function MpqAddFileFromBuffer Lib "SFmpq.dll" (ByVal hMPQ As Long, ByRef lpBuffer As Any, ByVal dwLength As Long, ByVal lpFileName As String, ByVal dwFlags As Long) As Boolean 323 | Declare Function MpqAddWaveFromBuffer Lib "SFmpq.dll" (ByVal hMPQ As Long, ByRef lpBuffer As Any, ByVal dwLength As Long, ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwQuality As Long) As Boolean 324 | Declare Function MpqRenameAndSetFileLocale Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpcOldFileName As String, ByVal lpcNewFileName As String, ByVal nOldLocale As Long, ByVal nNewLocale As Long) As Boolean 325 | Declare Function MpqDeleteFileWithLocale Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String, ByVal nLocale As Long) As Boolean 326 | Declare Function MpqSetFileLocale Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String, ByVal nOldLocale As Long, ByVal nNewLocale As Long) As Boolean 327 | 328 | ' These functions do nothing. They are only provided for 329 | ' compatibility with MPQ extractors that use storm. 330 | Declare Function SFileDestroy Lib "SFmpq.dll" () As Boolean 331 | Declare Sub StormDestroy Lib "SFmpq.dll" () 332 | 333 | ' Returns 0 if the dll version is equal to the version your program was compiled 334 | ' with, 1 if the dll is newer, -1 if the dll is older. 335 | Function SFMpqCompareVersion() As Long 336 | Dim ExeVersion As SFMPQVERSION, DllVersion As SFMPQVERSION 337 | With ExeVersion 338 | .Major = 1 339 | .Minor = 0 340 | .Revision = 8 341 | .Subrevision = 1 342 | End With 343 | DllVersion = SFMpqGetVersion() 344 | If DllVersion.Major > ExeVersion.Major Then 345 | SFMpqCompareVersion = 1 346 | Exit Function 347 | ElseIf DllVersion.Major < ExeVersion.Major Then 348 | SFMpqCompareVersion = -1 349 | Exit Function 350 | End If 351 | If DllVersion.Minor > ExeVersion.Minor Then 352 | SFMpqCompareVersion = 1 353 | Exit Function 354 | ElseIf DllVersion.Minor < ExeVersion.Minor Then 355 | SFMpqCompareVersion = -1 356 | Exit Function 357 | End If 358 | If DllVersion.Revision > ExeVersion.Revision Then 359 | SFMpqCompareVersion = 1 360 | Exit Function 361 | ElseIf DllVersion.Revision < ExeVersion.Revision Then 362 | SFMpqCompareVersion = -1 363 | Exit Function 364 | End If 365 | If DllVersion.Subrevision > ExeVersion.Subrevision Then 366 | SFMpqCompareVersion = 1 367 | Exit Function 368 | ElseIf DllVersion.Subrevision < ExeVersion.Subrevision Then 369 | SFMpqCompareVersion = -1 370 | Exit Function 371 | End If 372 | SFMpqCompareVersion = 0 373 | End Function 374 | 375 | -------------------------------------------------------------------------------- /SFmpqapi.def: -------------------------------------------------------------------------------- 1 | ; License information for this code is in license.txt 2 | 3 | EXPORTS 4 | MpqInitialize=MpqInitialize @1 5 | MpqGetVersion=MpqGetVersion @2 6 | MpqGetVersionString=MpqGetVersionString @3 7 | 8 | SFMpqGetVersionString=SFMpqGetVersionString @8 9 | SFMpqGetVersion=SFMpqGetVersion @9 10 | SFMpqGetVersionString2=SFMpqGetVersionString2 @10 11 | SFMpqDestroy=SFMpqDestroy @11 12 | AboutSFMpq=AboutSFMpq @12 13 | 14 | MpqOpenArchiveForUpdate=MpqOpenArchiveForUpdate @16 15 | MpqCloseUpdatedArchive=MpqCloseUpdatedArchive @17 16 | MpqAddFileToArchive=MpqAddFileToArchive @18 17 | MpqAddWaveToArchive=MpqAddWaveToArchive @19 18 | MpqRenameFile=MpqRenameFile @20 19 | MpqDeleteFile=MpqDeleteFile @21 20 | MpqCompactArchive=MpqCompactArchive @22 21 | 22 | MpqAddFileFromBuffer=MpqAddFileFromBuffer @23 23 | MpqSetFileLocale=MpqSetFileLocale @24 24 | MpqAddWaveFromBuffer=MpqAddWaveFromBuffer @25 25 | MpqAddFileToArchiveEx=MpqAddFileToArchiveEx @26 26 | MpqAddFileFromBufferEx=MpqAddFileFromBufferEx @27 27 | MpqRenameAndSetFileLocale=MpqRenameAndSetFileLocale @28 28 | MpqDeleteFileWithLocale=MpqDeleteFileWithLocale @29 29 | MpqOpenArchiveForUpdateEx=MpqOpenArchiveForUpdateEx @30 30 | 31 | ;Lmpqapi ordinals 32 | SFOpenArchive=SFileOpenArchive @32 NONAME 33 | SFCloseArchive=SFileCloseArchive @33 NONAME 34 | SFOpenFileEx=SFileOpenFileEx @34 NONAME 35 | SFCloseFile=SFileCloseFile @35 NONAME 36 | SFGetFileSize=SFileGetFileSize @36 NONAME 37 | SFileGetFileInfo=SFileGetFileInfo @37 38 | SFSetFilePointer=SFileSetFilePointer @38 NONAME 39 | SFReadFile=SFileReadFile @39 NONAME 40 | SFSetLocale=SFileSetLocale @40 NONAME 41 | 42 | SFOpenFile=SFileOpenFile @41 NONAME 43 | SFileSetArchivePriority=SFileSetArchivePriority @42 44 | SFileFindMpqHeader=SFileFindMpqHeader @43 45 | SFileListFiles=SFileListFiles @44 46 | 47 | ;Old Diablo Storm ordinals 48 | SFDCloseArchive=SFileCloseArchive @63 NONAME 49 | SFDCloseFile=SFileCloseFile @64 NONAME 50 | SFDDestroy=SFileDestroy @73 NONAME 51 | SFDGetFileArchive=SFileGetFileArchive @75 NONAME 52 | SFDGetFileSize=SFileGetFileSize @76 NONAME 53 | SFDOpenArchive=SFileOpenArchive @77 NONAME 54 | SFDOpenFile=SFileOpenFile @78 NONAME 55 | SFDOpenFileEx=SFileOpenFileEx @79 NONAME 56 | SFDReadFile=SFileReadFile @80 NONAME 57 | SFDSetBasePath=SFileSetBasePath @81 NONAME 58 | SFDSetFilePointer=SFileSetFilePointer @82 NONAME 59 | SFDSetLocale=SFileSetLocale @83 NONAME 60 | SFDGetBasePath=SFileGetBasePath @84 NONAME 61 | SFDGetArchiveName=SFileGetArchiveName @86 NONAME 62 | SFDGetFileName=SFileGetFileName @87 NONAME 63 | DStormDestroy=StormDestroy @112 NONAME 64 | 65 | ;Storm ordinals 66 | SFileCloseArchive=SFileCloseArchive @252 67 | SFileCloseFile=SFileCloseFile @253 68 | SFileDestroy=SFileDestroy @262 69 | SFileGetFileArchive=SFileGetFileArchive @264 70 | SFileGetFileSize=SFileGetFileSize @265 71 | SFileOpenArchive=SFileOpenArchive @266 72 | SFileOpenFile=SFileOpenFile @267 73 | SFileOpenFileEx=SFileOpenFileEx @268 74 | SFileReadFile=SFileReadFile @269 75 | SFileSetBasePath=SFileSetBasePath @270 76 | SFileSetFilePointer=SFileSetFilePointer @271 77 | SFileSetLocale=SFileSetLocale @272 78 | SFileGetBasePath=SFileGetBasePath @273 79 | SFileGetArchiveName=SFileGetArchiveName @275 80 | SFileGetFileName=SFileGetFileName @276 81 | SFileOpenFileAsArchive=SFileOpenFileAsArchive @293 82 | StormDestroy=StormDestroy @301 83 | SCompCompress=SCompCompress @551 NONAME 84 | SCompDecompress=SCompDecompress @552 NONAME 85 | 86 | ;Zlib exports 87 | adler32 88 | compress 89 | crc32 90 | deflate 91 | deflateCopy 92 | deflateEnd 93 | deflateInit2_ 94 | deflateInit_ 95 | deflateParams 96 | deflateReset 97 | deflateSetDictionary 98 | inflate 99 | inflateEnd 100 | inflateInit2_ 101 | inflateInit_ 102 | inflateReset 103 | inflateSetDictionary 104 | inflateSync 105 | uncompress 106 | zlibVersion 107 | zError 108 | inflateSyncPoint 109 | get_crc_table 110 | compress2 111 | 112 | ;bzip2 exports 113 | BZ2_bzCompressInit 114 | BZ2_bzCompress 115 | BZ2_bzCompressEnd 116 | BZ2_bzDecompressInit 117 | BZ2_bzDecompress 118 | BZ2_bzDecompressEnd 119 | BZ2_bzBuffToBuffCompress 120 | BZ2_bzBuffToBuffDecompress 121 | BZ2_bzlibVersion 122 | -------------------------------------------------------------------------------- /SFmpqapi.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="SFmpqapi" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 6 | 7 | CFG=SFmpqapi - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "SFmpqapi.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "SFmpqapi.mak" CFG="SFmpqapi - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "SFmpqapi - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") 21 | !MESSAGE "SFmpqapi - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") 22 | !MESSAGE "SFmpqapi - Win32 Beta release" (based on "Win32 (x86) Dynamic-Link Library") 23 | !MESSAGE 24 | 25 | # Begin Project 26 | # PROP AllowPerConfigDependencies 0 27 | # PROP Scc_ProjName "" 28 | # PROP Scc_LocalPath "" 29 | CPP=cl.exe 30 | MTL=midl.exe 31 | RSC=rc.exe 32 | 33 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 34 | 35 | # PROP BASE Use_MFC 0 36 | # PROP BASE Use_Debug_Libraries 0 37 | # PROP BASE Output_Dir "Release" 38 | # PROP BASE Intermediate_Dir "Release" 39 | # PROP BASE Target_Dir "" 40 | # PROP Use_MFC 0 41 | # PROP Use_Debug_Libraries 0 42 | # PROP Output_Dir "Release" 43 | # PROP Intermediate_Dir "Release" 44 | # PROP Ignore_Export_Lib 0 45 | # PROP Target_Dir "" 46 | # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SFMPQAPI_EXPORTS" /YX /FD /c 47 | # ADD CPP /nologo /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SFMPQAPI_EXPORTS" /D "ZLIB_DLL" /D "BZ_NO_STDIO" /FD /c 48 | # SUBTRACT CPP /YX 49 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 50 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 51 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 52 | # ADD RSC /l 0x409 /d "NDEBUG" 53 | BSC32=bscmake.exe 54 | # ADD BASE BSC32 /nologo 55 | # ADD BSC32 /nologo 56 | LINK32=link.exe 57 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 58 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"Release/SFmpq.dll" 59 | # SUBTRACT LINK32 /pdb:none 60 | 61 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 62 | 63 | # PROP BASE Use_MFC 0 64 | # PROP BASE Use_Debug_Libraries 1 65 | # PROP BASE Output_Dir "Debug" 66 | # PROP BASE Intermediate_Dir "Debug" 67 | # PROP BASE Target_Dir "" 68 | # PROP Use_MFC 0 69 | # PROP Use_Debug_Libraries 1 70 | # PROP Output_Dir "Debug" 71 | # PROP Intermediate_Dir "Debug" 72 | # PROP Ignore_Export_Lib 0 73 | # PROP Target_Dir "" 74 | # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SFMPQAPI_EXPORTS" /YX /FD /GZ /c 75 | # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SFMPQAPI_EXPORTS" /D "ZLIB_DLL" /D "BZ_NO_STDIO" /FD /GZ /c 76 | # SUBTRACT CPP /Fr /YX 77 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 78 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 79 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 80 | # ADD RSC /l 0x409 /d "_DEBUG" 81 | BSC32=bscmake.exe 82 | # ADD BASE BSC32 /nologo 83 | # ADD BSC32 /nologo 84 | LINK32=link.exe 85 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept 86 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"Debug/SFmpq.dll" /pdbtype:sept 87 | 88 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 89 | 90 | # PROP BASE Use_MFC 0 91 | # PROP BASE Use_Debug_Libraries 0 92 | # PROP BASE Output_Dir "SFmpqapi___Win32_Beta_release" 93 | # PROP BASE Intermediate_Dir "SFmpqapi___Win32_Beta_release" 94 | # PROP BASE Ignore_Export_Lib 0 95 | # PROP BASE Target_Dir "" 96 | # PROP Use_MFC 0 97 | # PROP Use_Debug_Libraries 0 98 | # PROP Output_Dir "Release" 99 | # PROP Intermediate_Dir "Release" 100 | # PROP Ignore_Export_Lib 0 101 | # PROP Target_Dir "" 102 | # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SFMPQAPI_EXPORTS" /YX /FD /c 103 | # ADD CPP /nologo /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SFMPQAPI_EXPORTS" /D "ZLIB_DLL" /D "BZ_NO_STDIO" /D "BETA" /FD /c 104 | # SUBTRACT CPP /YX 105 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 106 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 107 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 108 | # ADD RSC /l 0x409 /d "NDEBUG" /d "BETA" 109 | BSC32=bscmake.exe 110 | # ADD BASE BSC32 /nologo 111 | # ADD BSC32 /nologo 112 | LINK32=link.exe 113 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"Release/SFmpq.dll" 114 | # SUBTRACT BASE LINK32 /pdb:none 115 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"Release/SFmpq.dll" 116 | # SUBTRACT LINK32 /pdb:none 117 | 118 | !ENDIF 119 | 120 | # Begin Target 121 | 122 | # Name "SFmpqapi - Win32 Release" 123 | # Name "SFmpqapi - Win32 Debug" 124 | # Name "SFmpqapi - Win32 Beta release" 125 | # Begin Group "Source Files" 126 | 127 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 128 | # Begin Source File 129 | 130 | SOURCE=.\MpqBlockTable.cpp 131 | # End Source File 132 | # Begin Source File 133 | 134 | SOURCE=.\MpqCrypt.cpp 135 | # End Source File 136 | # Begin Source File 137 | 138 | SOURCE=.\MpqHashTable.cpp 139 | # End Source File 140 | # Begin Source File 141 | 142 | SOURCE=.\SFmpqapi.cpp 143 | # End Source File 144 | # Begin Source File 145 | 146 | SOURCE=.\SFmpqapi.def 147 | # End Source File 148 | # Begin Source File 149 | 150 | SOURCE=.\SFmpqapi.odl 151 | # End Source File 152 | # Begin Source File 153 | 154 | SOURCE=.\SFmpqapi.rc 155 | # End Source File 156 | # Begin Source File 157 | 158 | SOURCE=.\SFUtil.cpp 159 | # End Source File 160 | # End Group 161 | # Begin Group "Header Files" 162 | 163 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 164 | # Begin Source File 165 | 166 | SOURCE=.\MpqBlockTable.h 167 | # End Source File 168 | # Begin Source File 169 | 170 | SOURCE=.\MpqCrypt.h 171 | # End Source File 172 | # Begin Source File 173 | 174 | SOURCE=.\MpqHashTable.h 175 | # End Source File 176 | # Begin Source File 177 | 178 | SOURCE=.\SFmpqapi.h 179 | # End Source File 180 | # Begin Source File 181 | 182 | SOURCE=.\SFTypes.h 183 | # End Source File 184 | # Begin Source File 185 | 186 | SOURCE=.\SFUtil.h 187 | # End Source File 188 | # End Group 189 | # Begin Group "Resource Files" 190 | 191 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 192 | # Begin Source File 193 | 194 | SOURCE=.\about 195 | # End Source File 196 | # End Group 197 | # Begin Group "SComp" 198 | 199 | # PROP Default_Filter "" 200 | # Begin Group "Base" 201 | 202 | # PROP Default_Filter "" 203 | # Begin Group "Source Files (Base)" 204 | 205 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 206 | # Begin Source File 207 | 208 | SOURCE=..\SComp\explode.c 209 | 210 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 211 | 212 | # PROP Intermediate_Dir "Release/SComp" 213 | 214 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 215 | 216 | # PROP Intermediate_Dir "Debug/SComp" 217 | 218 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 219 | 220 | # PROP Intermediate_Dir "Release/SComp" 221 | 222 | !ENDIF 223 | 224 | # End Source File 225 | # Begin Source File 226 | 227 | SOURCE=..\SComp\huffman.cpp 228 | 229 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 230 | 231 | # PROP Intermediate_Dir "Release/SComp" 232 | 233 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 234 | 235 | # PROP Intermediate_Dir "Debug/SComp" 236 | 237 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 238 | 239 | # PROP Intermediate_Dir "Release/SComp" 240 | 241 | !ENDIF 242 | 243 | # End Source File 244 | # Begin Source File 245 | 246 | SOURCE=..\SComp\implode.c 247 | 248 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 249 | 250 | # PROP Intermediate_Dir "Release/SComp" 251 | 252 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 253 | 254 | # PROP Intermediate_Dir "Debug/SComp" 255 | 256 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 257 | 258 | # PROP Intermediate_Dir "Release/SComp" 259 | 260 | !ENDIF 261 | 262 | # End Source File 263 | # Begin Source File 264 | 265 | SOURCE=..\SComp\SComp.cpp 266 | 267 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 268 | 269 | # PROP Intermediate_Dir "Release/SComp" 270 | 271 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 272 | 273 | # PROP Intermediate_Dir "Debug/SComp" 274 | 275 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 276 | 277 | # PROP Intermediate_Dir "Release/SComp" 278 | 279 | !ENDIF 280 | 281 | # End Source File 282 | # Begin Source File 283 | 284 | SOURCE=..\SComp\SErr.cpp 285 | 286 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 287 | 288 | # PROP Intermediate_Dir "Release/SComp" 289 | 290 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 291 | 292 | # PROP Intermediate_Dir "Debug/SComp" 293 | 294 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 295 | 296 | # PROP Intermediate_Dir "Release/SComp" 297 | 298 | !ENDIF 299 | 300 | # End Source File 301 | # Begin Source File 302 | 303 | SOURCE=..\SComp\SMem.cpp 304 | 305 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 306 | 307 | # PROP Intermediate_Dir "Release/SComp" 308 | 309 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 310 | 311 | # PROP Intermediate_Dir "Debug/SComp" 312 | 313 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 314 | 315 | # PROP Intermediate_Dir "Release/SComp" 316 | 317 | !ENDIF 318 | 319 | # End Source File 320 | # Begin Source File 321 | 322 | SOURCE=..\SComp\wave.cpp 323 | 324 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 325 | 326 | # PROP Intermediate_Dir "Release/SComp" 327 | 328 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 329 | 330 | # PROP Intermediate_Dir "Debug/SComp" 331 | 332 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 333 | 334 | # PROP Intermediate_Dir "Release/SComp" 335 | 336 | !ENDIF 337 | 338 | # End Source File 339 | # End Group 340 | # Begin Group "Header Files (Base)" 341 | 342 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 343 | # Begin Source File 344 | 345 | SOURCE=..\SComp\Huffman.h 346 | # End Source File 347 | # Begin Source File 348 | 349 | SOURCE=..\SComp\pklib.h 350 | # End Source File 351 | # Begin Source File 352 | 353 | SOURCE=..\SComp\SComp.h 354 | # End Source File 355 | # Begin Source File 356 | 357 | SOURCE=..\SComp\SErr.h 358 | # End Source File 359 | # Begin Source File 360 | 361 | SOURCE=..\SComp\SMem.h 362 | # End Source File 363 | # Begin Source File 364 | 365 | SOURCE=..\SComp\wave.h 366 | # End Source File 367 | # End Group 368 | # End Group 369 | # Begin Group "bzip2" 370 | 371 | # PROP Default_Filter "" 372 | # Begin Group "Source Files (bzip2)" 373 | 374 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 375 | # Begin Source File 376 | 377 | SOURCE=..\SComp\bzip2\blocksort.c 378 | 379 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 380 | 381 | # PROP Intermediate_Dir "Release/SComp/bzip2" 382 | 383 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 384 | 385 | # PROP Intermediate_Dir "Debug/SComp/bzip2" 386 | 387 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 388 | 389 | # PROP Intermediate_Dir "Release/SComp/bzip2" 390 | 391 | !ENDIF 392 | 393 | # End Source File 394 | # Begin Source File 395 | 396 | SOURCE=..\SComp\bzip2\bzlib.c 397 | 398 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 399 | 400 | # PROP Intermediate_Dir "Release/SComp/bzip2" 401 | 402 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 403 | 404 | # PROP Intermediate_Dir "Debug/SComp/bzip2" 405 | 406 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 407 | 408 | # PROP Intermediate_Dir "Release/SComp/bzip2" 409 | 410 | !ENDIF 411 | 412 | # End Source File 413 | # Begin Source File 414 | 415 | SOURCE=..\SComp\bzip2\compress.c 416 | 417 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 418 | 419 | # PROP Intermediate_Dir "Release/SComp/bzip2" 420 | 421 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 422 | 423 | # PROP Intermediate_Dir "Debug/SComp/bzip2" 424 | 425 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 426 | 427 | # PROP Intermediate_Dir "Release/SComp/bzip2" 428 | 429 | !ENDIF 430 | 431 | # End Source File 432 | # Begin Source File 433 | 434 | SOURCE=..\SComp\bzip2\crctable.c 435 | 436 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 437 | 438 | # PROP Intermediate_Dir "Release/SComp/bzip2" 439 | 440 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 441 | 442 | # PROP Intermediate_Dir "Debug/SComp/bzip2" 443 | 444 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 445 | 446 | # PROP Intermediate_Dir "Release/SComp/bzip2" 447 | 448 | !ENDIF 449 | 450 | # End Source File 451 | # Begin Source File 452 | 453 | SOURCE=..\SComp\bzip2\decompress.c 454 | 455 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 456 | 457 | # PROP Intermediate_Dir "Release/SComp/bzip2" 458 | 459 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 460 | 461 | # PROP Intermediate_Dir "Debug/SComp/bzip2" 462 | 463 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 464 | 465 | # PROP Intermediate_Dir "Release/SComp/bzip2" 466 | 467 | !ENDIF 468 | 469 | # End Source File 470 | # Begin Source File 471 | 472 | SOURCE=..\SComp\bzip2\huffman.c 473 | 474 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 475 | 476 | # PROP Intermediate_Dir "Release/SComp/bzip2" 477 | 478 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 479 | 480 | # PROP Intermediate_Dir "Debug/SComp/bzip2" 481 | 482 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 483 | 484 | # PROP Intermediate_Dir "Release/SComp/bzip2" 485 | 486 | !ENDIF 487 | 488 | # End Source File 489 | # Begin Source File 490 | 491 | SOURCE=..\SComp\bzip2\randtable.c 492 | 493 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 494 | 495 | # PROP Intermediate_Dir "Release/SComp/bzip2" 496 | 497 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 498 | 499 | # PROP Intermediate_Dir "Debug/SComp/bzip2" 500 | 501 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 502 | 503 | # PROP Intermediate_Dir "Release/SComp/bzip2" 504 | 505 | !ENDIF 506 | 507 | # End Source File 508 | # End Group 509 | # Begin Group "Header Files (bzip2)" 510 | 511 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 512 | # Begin Source File 513 | 514 | SOURCE=..\SComp\bzip2\bzlib.h 515 | # End Source File 516 | # Begin Source File 517 | 518 | SOURCE=..\SComp\bzip2\bzlib_private.h 519 | # End Source File 520 | # End Group 521 | # End Group 522 | # Begin Group "zlib" 523 | 524 | # PROP Default_Filter "" 525 | # Begin Group "Source Files (zlib)" 526 | 527 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 528 | # Begin Source File 529 | 530 | SOURCE=..\SComp\zlib\adler32.c 531 | 532 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 533 | 534 | # PROP Intermediate_Dir "Release/SComp/zlib" 535 | 536 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 537 | 538 | # PROP Intermediate_Dir "Debug/SComp/zlib" 539 | 540 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 541 | 542 | # PROP Intermediate_Dir "Release/SComp/zlib" 543 | 544 | !ENDIF 545 | 546 | # End Source File 547 | # Begin Source File 548 | 549 | SOURCE=..\SComp\zlib\compress.c 550 | 551 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 552 | 553 | # PROP Intermediate_Dir "Release/SComp/zlib" 554 | 555 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 556 | 557 | # PROP Intermediate_Dir "Debug/SComp/zlib" 558 | 559 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 560 | 561 | # PROP Intermediate_Dir "Release/SComp/zlib" 562 | 563 | !ENDIF 564 | 565 | # End Source File 566 | # Begin Source File 567 | 568 | SOURCE=..\SComp\zlib\crc32.c 569 | 570 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 571 | 572 | # PROP Intermediate_Dir "Release/SComp/zlib" 573 | 574 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 575 | 576 | # PROP Intermediate_Dir "Debug/SComp/zlib" 577 | 578 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 579 | 580 | # PROP Intermediate_Dir "Release/SComp/zlib" 581 | 582 | !ENDIF 583 | 584 | # End Source File 585 | # Begin Source File 586 | 587 | SOURCE=..\SComp\zlib\deflate.c 588 | 589 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 590 | 591 | # PROP Intermediate_Dir "Release/SComp/zlib" 592 | 593 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 594 | 595 | # PROP Intermediate_Dir "Debug/SComp/zlib" 596 | 597 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 598 | 599 | # PROP Intermediate_Dir "Release/SComp/zlib" 600 | 601 | !ENDIF 602 | 603 | # End Source File 604 | # Begin Source File 605 | 606 | SOURCE=..\SComp\zlib\inffast.c 607 | 608 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 609 | 610 | # PROP Intermediate_Dir "Release/SComp/zlib" 611 | 612 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 613 | 614 | # PROP Intermediate_Dir "Debug/SComp/zlib" 615 | 616 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 617 | 618 | # PROP Intermediate_Dir "Release/SComp/zlib" 619 | 620 | !ENDIF 621 | 622 | # End Source File 623 | # Begin Source File 624 | 625 | SOURCE=..\SComp\zlib\inflate.c 626 | 627 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 628 | 629 | # PROP Intermediate_Dir "Release/SComp/zlib" 630 | 631 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 632 | 633 | # PROP Intermediate_Dir "Debug/SComp/zlib" 634 | 635 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 636 | 637 | # PROP Intermediate_Dir "Release/SComp/zlib" 638 | 639 | !ENDIF 640 | 641 | # End Source File 642 | # Begin Source File 643 | 644 | SOURCE=..\SComp\zlib\inftrees.c 645 | 646 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 647 | 648 | # PROP Intermediate_Dir "Release/SComp/zlib" 649 | 650 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 651 | 652 | # PROP Intermediate_Dir "Debug/SComp/zlib" 653 | 654 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 655 | 656 | # PROP Intermediate_Dir "Release/SComp/zlib" 657 | 658 | !ENDIF 659 | 660 | # End Source File 661 | # Begin Source File 662 | 663 | SOURCE=..\SComp\zlib\trees.c 664 | 665 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 666 | 667 | # PROP Intermediate_Dir "Release/SComp/zlib" 668 | 669 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 670 | 671 | # PROP Intermediate_Dir "Debug/SComp/zlib" 672 | 673 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 674 | 675 | # PROP Intermediate_Dir "Release/SComp/zlib" 676 | 677 | !ENDIF 678 | 679 | # End Source File 680 | # Begin Source File 681 | 682 | SOURCE=..\SComp\zlib\uncompr.c 683 | 684 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 685 | 686 | # PROP Intermediate_Dir "Release/SComp/zlib" 687 | 688 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 689 | 690 | # PROP Intermediate_Dir "Debug/SComp/zlib" 691 | 692 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 693 | 694 | # PROP Intermediate_Dir "Release/SComp/zlib" 695 | 696 | !ENDIF 697 | 698 | # End Source File 699 | # Begin Source File 700 | 701 | SOURCE=..\SComp\zlib\zutil.c 702 | 703 | !IF "$(CFG)" == "SFmpqapi - Win32 Release" 704 | 705 | # PROP Intermediate_Dir "Release/SComp/zlib" 706 | 707 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Debug" 708 | 709 | # PROP Intermediate_Dir "Debug/SComp/zlib" 710 | 711 | !ELSEIF "$(CFG)" == "SFmpqapi - Win32 Beta release" 712 | 713 | # PROP Intermediate_Dir "Release/SComp/zlib" 714 | 715 | !ENDIF 716 | 717 | # End Source File 718 | # End Group 719 | # Begin Group "Header Files (zlib)" 720 | 721 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 722 | # Begin Source File 723 | 724 | SOURCE=..\SComp\zlib\zconf.h 725 | # End Source File 726 | # Begin Source File 727 | 728 | SOURCE=..\SComp\zlib\zlib.h 729 | # End Source File 730 | # End Group 731 | # End Group 732 | # End Group 733 | # End Target 734 | # End Project 735 | -------------------------------------------------------------------------------- /SFmpqapi.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "SFmpqapi"=".\SFmpqapi.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Project: "SFmpqlib"=".\SFmpqlib.dsp" - Package Owner=<4> 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<4> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | Global: 31 | 32 | Package=<5> 33 | {{{ 34 | }}} 35 | 36 | Package=<3> 37 | {{{ 38 | }}} 39 | 40 | ############################################################################### 41 | 42 | -------------------------------------------------------------------------------- /SFmpqapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ShadowFlare MPQ API Library. (c) ShadowFlare Software 2002-2010 4 | License information for this code is in license.txt and 5 | included in this file at the end of this comment. 6 | 7 | All functions below are actual functions that are part of this 8 | library and do not need any additional dll files. It does not 9 | even require Storm to be able to decompress or compress files. 10 | 11 | This library emulates the interface of Lmpqapi and Storm MPQ 12 | functions, so it may be used as a replacement for them in 13 | MPQ extractors/archivers without even needing to recompile 14 | the program that uses Lmpqapi or Storm. It has a few features 15 | not included in Lmpqapi and Storm, such as extra flags for some 16 | functions, setting the locale ID of existing files, and adding 17 | files without having to write them somewhere else first. Also, 18 | MPQ handles used by functions prefixed with "SFile" and "Mpq" 19 | can be used interchangably; all functions use the same type 20 | of MPQ handles. You cannot, however, use handles from this 21 | library with storm or lmpqapi or vice-versa. Doing so will 22 | most likely result in a crash. 23 | 24 | Revision History: 25 | (Release date) 1.08 (ShadowFlare) 26 | - Fixed a buffer overflow that would occur when reading files 27 | if neither using a buffer that is large enough to contain the 28 | entire file nor has a size that is a multiple of 4096 29 | - Added SFileOpenFileAsArchive which opens an archive that is 30 | contained within an already open archive 31 | - Added MpqRenameAndSetFileLocale and MpqDeleteFileWithLocale. 32 | These have extra parameters that allow you to use them with 33 | files having language codes other than what was last set 34 | using SFileSetLocale 35 | - Fixed a bug that caused (listfile) to get cleared if adding 36 | files with a locale ID other than 0 37 | - Added MpqOpenArchiveForUpdateEx which allows creating 38 | archives with different block sizes 39 | - SFileListFiles can list the contents of bncache.dat without 40 | needing an external list 41 | 42 | 06/12/2002 1.07 (ShadowFlare) 43 | - No longer requires Storm.dll to compress or decompress 44 | Warcraft III files 45 | - Added SFileListFiles for getting names and information 46 | about all of the files in an archive 47 | - Fixed a bug with renaming and deleting files 48 | - Fixed a bug with adding wave compressed files with 49 | low compression setting 50 | - Added a check in MpqOpenArchiveForUpdate for proper 51 | dwMaximumFilesInArchive values (should be a number that 52 | is a power of 2). If it is not a proper value, it will 53 | be rounded up to the next higher power of 2 54 | 55 | 05/09/2002 1.06 (ShadowFlare) 56 | - Compresses files without Storm.dll! 57 | - If Warcraft III is installed, this library will be able to 58 | find Storm.dll on its own. (Storm.dll is needed to 59 | decompress Warcraft III files) 60 | - Fixed a bug where an embedded archive and the file that 61 | contains it would be corrupted if the archive was modified 62 | - Able to open all .w3m maps now 63 | 64 | 29/06/2002 1.05 (ShadowFlare) 65 | - Supports decompressing files from Warcraft III MPQ archives 66 | if using Storm.dll from Warcraft III 67 | - Added MpqAddFileToArchiveEx and MpqAddFileFromBufferEx for 68 | using extra compression types 69 | 70 | 29/05/2002 1.04 (ShadowFlare) 71 | - Files can be compressed now! 72 | - Fixed a bug in SFileReadFile when reading data not aligned 73 | to the block size 74 | - Optimized some of SFileReadFile's code. It can read files 75 | faster now 76 | - SFile functions may now be used to access files not in mpq 77 | archives as you can with the real storm functions 78 | - MpqCompactArchive will no longer corrupt files with the 79 | MODCRYPTKEY flag as long as the file is either compressed, 80 | listed in "(listfile)", is "(listfile)", or is located in 81 | the same place in the compacted archive; so it is safe 82 | enough to use it on almost any archive 83 | - Added MpqAddWaveFromBuffer 84 | - Better handling of archives with no files 85 | - Fixed compression with COMPRESS2 flag 86 | 87 | 15/05/2002 1.03 (ShadowFlare) 88 | - Supports adding files with the compression attribute (does 89 | not actually compress files). Now archives created with 90 | this dll can have files added to them through lmpqapi 91 | without causing staredit to crash 92 | - SFileGetBasePath and SFileSetBasePath work more like their 93 | Storm equivalents now 94 | - Implemented MpqCompactArchive, but it is not finished yet. 95 | In its current state, I would recommend against using it 96 | on archives that contain files with the MODCRYPTKEY flag, 97 | since it will corrupt any files with that flag 98 | - Added SFMpqGetVersionString2 which may be used in Visual 99 | Basic to get the version string 100 | 101 | 07/05/2002 1.02 (ShadowFlare) 102 | - SFileReadFile no longer passes the lpOverlapped parameter it 103 | receives to ReadFile. This is what was causing the function 104 | to fail when used in Visual Basic 105 | - Added support for more Storm MPQ functions 106 | - GetLastError may now be used to get information about why a 107 | function failed 108 | 109 | 01/05/2002 1.01 (ShadowFlare) 110 | - Added ordinals for Storm MPQ functions 111 | - Fixed MPQ searching functionality of SFileOpenFileEx 112 | - Added a check for whether a valid handle is given when 113 | SFileCloseArchive is called 114 | - Fixed functionality of SFileSetArchivePriority when multiple 115 | files are open 116 | - File renaming works for all filenames now 117 | - SFileReadFile no longer reallocates the buffer for each block 118 | that is decompressed. This should make SFileReadFile at least 119 | a little faster 120 | 121 | 30/04/2002 1.00 (ShadowFlare) 122 | - First version. 123 | - Compression not yet supported 124 | - Does not use SetLastError yet, so GetLastError will not return any 125 | errors that have to do with this library 126 | - MpqCompactArchive not implemented 127 | 128 | Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare) 129 | 130 | License information: 131 | 132 | Copyright (c) 2002-2010, ShadowFlare 133 | All rights reserved. 134 | 135 | Redistribution and use in source and binary forms, with or without 136 | modification, are permitted provided that the following conditions 137 | are met: 138 | 139 | 1. Redistributions of source code must retain the above copyright 140 | notice, this list of conditions and the following disclaimer. 141 | 2. Redistributions in binary form must reproduce the above copyright 142 | notice, this list of conditions and the following disclaimer in the 143 | documentation and/or other materials provided with the distribution. 144 | 145 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND 146 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 147 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 148 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 149 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 150 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 151 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 152 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 153 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 154 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 155 | SUCH DAMAGE. 156 | */ 157 | 158 | #ifndef SHADOWFLARE_MPQ_API_INCLUDED 159 | #define SHADOWFLARE_MPQ_API_INCLUDED 160 | 161 | #include 162 | 163 | #ifndef SFMPQ_STATIC 164 | 165 | #ifdef SFMPQAPI_EXPORTS 166 | #define SFMPQAPI __declspec(dllexport) 167 | #else 168 | #define SFMPQAPI __declspec(dllimport) 169 | #endif 170 | 171 | #else 172 | #define SFMPQAPI 173 | #endif 174 | 175 | #ifdef __cplusplus 176 | extern "C" { 177 | #endif 178 | 179 | typedef struct { 180 | WORD Major; 181 | WORD Minor; 182 | WORD Revision; 183 | WORD Subrevision; 184 | } SFMPQVERSION; 185 | 186 | // MpqInitialize does nothing. It is only provided for 187 | // compatibility with MPQ archivers that use lmpqapi. 188 | BOOL SFMPQAPI WINAPI MpqInitialize(); 189 | 190 | LPCSTR SFMPQAPI WINAPI MpqGetVersionString(); 191 | float SFMPQAPI WINAPI MpqGetVersion(); 192 | 193 | void SFMPQAPI WINAPI SFMpqDestroy(); // This no longer needs to be called. It is only provided for compatibility with older versions 194 | 195 | void SFMPQAPI WINAPI AboutSFMpq(); // Displays an about page in a web browser (this has only been tested in Internet Explorer). This is only for the dll version of SFmpq 196 | 197 | // SFMpqGetVersionString2's return value is the required length of the buffer plus 198 | // the terminating null, so use SFMpqGetVersionString2(0, 0); to get the length. 199 | LPCSTR SFMPQAPI WINAPI SFMpqGetVersionString(); 200 | DWORD SFMPQAPI WINAPI SFMpqGetVersionString2(LPSTR lpBuffer, DWORD dwBufferLength); 201 | SFMPQVERSION SFMPQAPI WINAPI SFMpqGetVersion(); 202 | 203 | // Returns 0 if the dll version is equal to the version your program was compiled 204 | // with, 1 if the dll is newer, -1 if the dll is older. 205 | long SFMPQAPI __inline SFMpqCompareVersion(); 206 | 207 | // General error codes 208 | #define MPQ_ERROR_MPQ_INVALID 0x85200065 209 | #define MPQ_ERROR_FILE_NOT_FOUND 0x85200066 210 | #define MPQ_ERROR_DISK_FULL 0x85200068 //Physical write file to MPQ failed 211 | #define MPQ_ERROR_HASH_TABLE_FULL 0x85200069 212 | #define MPQ_ERROR_ALREADY_EXISTS 0x8520006A 213 | #define MPQ_ERROR_BAD_OPEN_MODE 0x8520006C //When MOAU_READ_ONLY is used without MOAU_OPEN_EXISTING 214 | 215 | #define MPQ_ERROR_COMPACT_ERROR 0x85300001 216 | 217 | // MpqOpenArchiveForUpdate flags 218 | #define MOAU_CREATE_NEW 0x00 //If archive does not exist, it will be created. If it exists, the function will fail 219 | #define MOAU_CREATE_ALWAYS 0x08 //Will always create a new archive 220 | #define MOAU_OPEN_EXISTING 0x04 //If archive exists, it will be opened. If it does not exist, the function will fail 221 | #define MOAU_OPEN_ALWAYS 0x20 //If archive exists, it will be opened. If it does not exist, it will be created 222 | #define MOAU_READ_ONLY 0x10 //Must be used with MOAU_OPEN_EXISTING. Archive will be opened without write access 223 | #define MOAU_MAINTAIN_ATTRIBUTES 0x02 //Will be used in a future version to create the (attributes) file 224 | #define MOAU_MAINTAIN_LISTFILE 0x01 //Creates and maintains a list of files in archive when they are added, replaced, or deleted 225 | 226 | // MpqOpenArchiveForUpdateEx constants 227 | #define DEFAULT_BLOCK_SIZE 3 // 512 << number = block size 228 | #define USE_DEFAULT_BLOCK_SIZE 0xFFFFFFFF // Use default block size that is defined internally 229 | 230 | // MpqAddFileToArchive flags 231 | #define MAFA_EXISTS 0x80000000 //This flag will be added if not present 232 | #define MAFA_UNKNOWN40000000 0x40000000 //Unknown flag 233 | #define MAFA_SINGLEBLOCK 0x01000000 //File is stored as a single unit rather than being split by the block size 234 | #define MAFA_MODCRYPTKEY 0x00020000 //Used with MAFA_ENCRYPT. Uses an encryption key based on file position and size 235 | #define MAFA_ENCRYPT 0x00010000 //Encrypts the file. The file is still accessible when using this, so the use of this has depreciated 236 | #define MAFA_COMPRESS 0x00000200 //File is to be compressed when added. This is used for most of the compression methods 237 | #define MAFA_COMPRESS2 0x00000100 //File is compressed with standard compression only (was used in Diablo 1) 238 | #define MAFA_REPLACE_EXISTING 0x00000001 //If file already exists, it will be replaced 239 | 240 | // MpqAddFileToArchiveEx compression flags 241 | #define MAFA_COMPRESS_STANDARD 0x08 //Standard PKWare DCL compression 242 | #define MAFA_COMPRESS_DEFLATE 0x02 //ZLib's deflate compression 243 | #define MAFA_COMPRESS_BZIP2 0x10 //bzip2 compression 244 | #define MAFA_COMPRESS_WAVE 0x81 //Stereo wave compression 245 | #define MAFA_COMPRESS_WAVE2 0x41 //Mono wave compression 246 | 247 | // Flags for individual compression types used for wave compression 248 | #define MAFA_COMPRESS_WAVECOMP1 0x80 //Main compressor for stereo wave compression 249 | #define MAFA_COMPRESS_WAVECOMP2 0x40 //Main compressor for mono wave compression 250 | #define MAFA_COMPRESS_WAVECOMP3 0x01 //Secondary compressor for wave compression 251 | 252 | // ZLib deflate compression level constants (used with MpqAddFileToArchiveEx and MpqAddFileFromBufferEx) 253 | #define Z_NO_COMPRESSION 0 254 | #define Z_BEST_SPEED 1 255 | #define Z_BEST_COMPRESSION 9 256 | #define Z_DEFAULT_COMPRESSION (-1) //Default level is 6 with current ZLib version 257 | 258 | // MpqAddWaveToArchive quality flags 259 | #define MAWA_QUALITY_HIGH 1 //Higher compression, lower quality 260 | #define MAWA_QUALITY_MEDIUM 0 //Medium compression, medium quality 261 | #define MAWA_QUALITY_LOW 2 //Lower compression, higher quality 262 | 263 | // SFileGetFileInfo flags 264 | #define SFILE_INFO_BLOCK_SIZE 0x01 //Block size in MPQ 265 | #define SFILE_INFO_HASH_TABLE_SIZE 0x02 //Hash table size in MPQ 266 | #define SFILE_INFO_NUM_FILES 0x03 //Number of files in MPQ 267 | #define SFILE_INFO_TYPE 0x04 //Is MPQHANDLE a file or an MPQ? 268 | #define SFILE_INFO_SIZE 0x05 //Size of MPQ or uncompressed file 269 | #define SFILE_INFO_COMPRESSED_SIZE 0x06 //Size of compressed file 270 | #define SFILE_INFO_FLAGS 0x07 //File flags (compressed, etc.), file attributes if a file not in an archive 271 | #define SFILE_INFO_PARENT 0x08 //Handle of MPQ that file is in 272 | #define SFILE_INFO_POSITION 0x09 //Position of file pointer in files 273 | #define SFILE_INFO_LOCALEID 0x0A //Locale ID of file in MPQ 274 | #define SFILE_INFO_PRIORITY 0x0B //Priority of open MPQ 275 | #define SFILE_INFO_HASH_INDEX 0x0C //Hash table index of file in MPQ 276 | #define SFILE_INFO_BLOCK_INDEX 0x0D //Block table index of file in MPQ 277 | 278 | // Return values of SFileGetFileInfo when SFILE_INFO_TYPE flag is used 279 | #define SFILE_TYPE_MPQ 0x01 280 | #define SFILE_TYPE_FILE 0x02 281 | 282 | // SFileListFiles flags 283 | #define SFILE_LIST_MEMORY_LIST 0x01 // Specifies that lpFilelists is a file list from memory, rather than being a list of file lists 284 | #define SFILE_LIST_ONLY_KNOWN 0x02 // Only list files that the function finds a name for 285 | #define SFILE_LIST_ONLY_UNKNOWN 0x04 // Only list files that the function does not find a name for 286 | #define SFILE_LIST_FLAG_UNKNOWN 0x08 // Use without SFILE_LIST_ONLY_KNOWN or SFILE_LIST_FLAG_UNKNOWN to list all files, but will set dwFileExists to 3 if file's name is not found 287 | 288 | // SFileOpenArchive flags 289 | #define SFILE_OPEN_HARD_DISK_FILE 0x0000 //Open archive without regard to the drive type it resides on 290 | #define SFILE_OPEN_CD_ROM_FILE 0x0001 //Open the archive only if it is on a CD-ROM 291 | #define SFILE_OPEN_ALLOW_WRITE 0x8000 //Open file with write access 292 | 293 | // SFileOpenFileEx search scopes 294 | #define SFILE_SEARCH_CURRENT_ONLY 0x00 //Used with SFileOpenFileEx; only the archive with the handle specified will be searched for the file 295 | #define SFILE_SEARCH_ALL_OPEN 0x01 //SFileOpenFileEx will look through all open archives for the file. This flag also allows files outside the archive to be used 296 | 297 | typedef HANDLE MPQHANDLE; 298 | 299 | #include 300 | 301 | struct FILELISTENTRY { 302 | DWORD dwFileExists; // Nonzero if this entry is used 303 | LCID lcLocale; // Locale ID of file 304 | DWORD dwCompressedSize; // Compressed size of file 305 | DWORD dwFullSize; // Uncompressed size of file 306 | DWORD dwFlags; // Flags for file 307 | char szFileName[260]; 308 | }; 309 | 310 | struct MPQARCHIVE; 311 | struct MPQFILE; 312 | struct MPQHEADER; 313 | struct BLOCKTABLEENTRY; 314 | struct HASHTABLEENTRY; 315 | 316 | struct MPQHEADER { 317 | DWORD dwMPQID; //"MPQ\x1A" for mpq's, "BN3\x1A" for bncache.dat 318 | DWORD dwHeaderSize; // Size of this header 319 | DWORD dwMPQSize; //The size of the mpq archive 320 | WORD wUnused0C; // Seems to always be 0 321 | WORD wBlockSize; // Size of blocks in files equals 512 << wBlockSize 322 | DWORD dwHashTableOffset; // Offset to hash table 323 | DWORD dwBlockTableOffset; // Offset to block table 324 | DWORD dwHashTableSize; // Number of entries in hash table 325 | DWORD dwBlockTableSize; // Number of entries in block table 326 | }; 327 | 328 | #include 329 | 330 | //Archive handles may be typecasted to this struct so you can access 331 | //some of the archive's properties and the decrypted hash table and 332 | //block table directly. This struct is based on Storm's internal 333 | //struct for archive handles. 334 | struct MPQARCHIVE { 335 | // Arranged according to priority with lowest priority first 336 | MPQARCHIVE * lpNextArc; //0// Pointer to the next MPQARCHIVE struct. Pointer to addresses of first and last archives if last archive 337 | MPQARCHIVE * lpPrevArc; //4// Pointer to the previous MPQARCHIVE struct. 0xEAFC5E23 if first archive 338 | char szFileName[260]; //8// Filename of the archive 339 | HANDLE hFile; //10C// The archive's file handle 340 | DWORD dwFlags1; //110// Some flags, bit 0 seems to be set when opening an archive from a hard drive if bit 1 in the flags for SFileOpenArchive is set, bit 1 (0 based) seems to be set when opening an archive from a CD 341 | DWORD dwPriority; //114// Priority of the archive set when calling SFileOpenArchive 342 | MPQFILE * lpLastReadFile; //118// Pointer to the last read file's MPQFILE struct. This is cleared when finished reading a block 343 | DWORD dwUnk; //11C// Seems to always be 0 344 | DWORD dwBlockSize; //120// Size of file blocks in bytes 345 | BYTE * lpLastReadBlock; //124// Pointer to the read buffer for archive. This is cleared when finished reading a block 346 | DWORD dwBufferSize; //128// Size of the read buffer for archive. This is cleared when finished reading a block 347 | DWORD dwMPQStart; //12C// The starting offset of the archive 348 | DWORD dwMPQEnd; //130// The ending offset of the archive 349 | MPQHEADER * lpMPQHeader; //134// Pointer to the archive header 350 | BLOCKTABLEENTRY * lpBlockTable; //138// Pointer to the start of the block table 351 | HASHTABLEENTRY * lpHashTable; //13C// Pointer to the start of the hash table 352 | DWORD dwReadOffset; //140// Offset to the data for a file 353 | DWORD dwRefCount; //144// Count of references to this open archive. This is incremented for each file opened from the archive, and decremented for each file closed 354 | // Extra struct members used by SFmpq 355 | MPQHEADER MpqHeader; 356 | DWORD dwFlags; //The only flags that should be changed are MOAU_MAINTAIN_LISTFILE and MOAU_MAINTAIN_ATTRIBUTES, changing any others can have unpredictable effects 357 | LPSTR lpFileName; 358 | DWORD dwExtraFlags; 359 | }; 360 | 361 | //Handles to files in the archive may be typecasted to this struct 362 | //so you can access some of the file's properties directly. This 363 | //struct is based on Storm's internal struct for file handles. 364 | struct MPQFILE { 365 | MPQFILE * lpNextFile; //0// Pointer to the next MPQFILE struct. Pointer to addresses of first and last files if last file 366 | MPQFILE * lpPrevFile; //4// Pointer to the previous MPQFILE struct. 0xEAFC5E13 if first file 367 | char szFileName[260]; //8// Filename of the file 368 | HANDLE hFile; //10C// Always INVALID_HANDLE_VALUE for files in MPQ archives. For files not in MPQ archives, this is the file handle for the file and the rest of this struct is filled with zeros except for dwRefCount 369 | MPQARCHIVE * lpParentArc; //110// Pointer to the MPQARCHIVE struct of the archive in which the file is contained 370 | BLOCKTABLEENTRY * lpBlockEntry; //114// Pointer to the file's block table entry 371 | DWORD dwCryptKey; //118// Decryption key for the file 372 | DWORD dwFilePointer; //11C// Position of file pointer in the file 373 | DWORD dwUnk; //120// Seems to always be 0 374 | DWORD dwBlockCount; //124// Number of blocks in file 375 | DWORD * lpdwBlockOffsets; //128// Offsets to blocks in file. There are 1 more of these than the number of blocks. The values for this are set after the first read 376 | DWORD dwReadStarted; //12C// Set to 1 after first read 377 | BOOL bStreaming; //130// 1 when streaming a WAVE 378 | BYTE * lpLastReadBlock; //134// Pointer to the read buffer for file. This starts at the position specified in the last SFileSetFilePointer call. This is cleared when SFileSetFilePointer is called or when finished reading the block 379 | DWORD dwBytesRead; //138// Total bytes read from the current block in the open file. This is cleared when SFileSetFilePointer is called or when finished reading the block 380 | DWORD dwBufferSize; //13C// Size of the read buffer for file. This is cleared when SFileSetFilePointer is called or when finished reading the block 381 | DWORD dwRefCount; //140// Count of references to this open file 382 | // Extra struct members used by SFmpq 383 | HASHTABLEENTRY *lpHashEntry; 384 | LPSTR lpFileName; 385 | }; 386 | 387 | #include 388 | 389 | struct BLOCKTABLEENTRY { 390 | DWORD dwFileOffset; // Offset to file 391 | DWORD dwCompressedSize; // Compressed size of file 392 | DWORD dwFullSize; // Uncompressed size of file 393 | DWORD dwFlags; // Flags for file 394 | }; 395 | 396 | struct HASHTABLEENTRY { 397 | DWORD dwNameHashA; // First name hash of file 398 | DWORD dwNameHashB; // Second name hash of file 399 | LCID lcLocale; // Locale ID of file 400 | DWORD dwBlockTableIndex; // Index to the block table entry for the file 401 | }; 402 | 403 | #include 404 | 405 | // Defines for backward compatibility with old lmpqapi function names 406 | #define MpqAddFileToArcive MpqAddFileToArchive 407 | #define MpqOpenArchive SFileOpenArchive 408 | #define MpqOpenFileEx SFileOpenFileEx 409 | #define MpqGetFileSize SFileGetFileSize 410 | #define MpqReadFile SFileReadFile 411 | #define MpqCloseFile SFileCloseFile 412 | #define MpqCloseArchive SFileCloseArchive 413 | 414 | // Storm functions implemented by this library 415 | BOOL SFMPQAPI WINAPI SFileOpenArchive(LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ); 416 | BOOL SFMPQAPI WINAPI SFileCloseArchive(MPQHANDLE hMPQ); 417 | BOOL SFMPQAPI WINAPI SFileOpenFileAsArchive(MPQHANDLE hSourceMPQ, LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ); 418 | BOOL SFMPQAPI WINAPI SFileGetArchiveName(MPQHANDLE hMPQ, LPSTR lpBuffer, DWORD dwBufferLength); 419 | BOOL SFMPQAPI WINAPI SFileOpenFile(LPCSTR lpFileName, MPQHANDLE *hFile); 420 | BOOL SFMPQAPI WINAPI SFileOpenFileEx(MPQHANDLE hMPQ, LPCSTR lpFileName, DWORD dwSearchScope, MPQHANDLE *hFile); 421 | BOOL SFMPQAPI WINAPI SFileCloseFile(MPQHANDLE hFile); 422 | DWORD SFMPQAPI WINAPI SFileGetFileSize(MPQHANDLE hFile, LPDWORD lpFileSizeHigh); 423 | BOOL SFMPQAPI WINAPI SFileGetFileArchive(MPQHANDLE hFile, MPQHANDLE *hMPQ); 424 | BOOL SFMPQAPI WINAPI SFileGetFileName(MPQHANDLE hFile, LPSTR lpBuffer, DWORD dwBufferLength); 425 | DWORD SFMPQAPI WINAPI SFileSetFilePointer(MPQHANDLE hFile, LONG lDistanceToMove, PLONG lplDistanceToMoveHigh, DWORD dwMoveMethod); 426 | BOOL SFMPQAPI WINAPI SFileReadFile(MPQHANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped); 427 | LCID SFMPQAPI WINAPI SFileSetLocale(LCID nNewLocale); 428 | BOOL SFMPQAPI WINAPI SFileGetBasePath(LPCSTR lpBuffer, DWORD dwBufferLength); 429 | BOOL SFMPQAPI WINAPI SFileSetBasePath(LPCSTR lpNewBasePath); 430 | 431 | // Extra storm-related functions 432 | DWORD SFMPQAPI WINAPI SFileGetFileInfo(MPQHANDLE hFile, DWORD dwInfoType); 433 | BOOL SFMPQAPI WINAPI SFileSetArchivePriority(MPQHANDLE hMPQ, DWORD dwPriority); 434 | DWORD SFMPQAPI WINAPI SFileFindMpqHeader(HANDLE hFile); 435 | BOOL SFMPQAPI WINAPI SFileListFiles(MPQHANDLE hMPQ, LPCSTR lpFileLists, FILELISTENTRY *lpListBuffer, DWORD dwFlags); 436 | 437 | // Archive editing functions implemented by this library 438 | MPQHANDLE SFMPQAPI WINAPI MpqOpenArchiveForUpdate(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive); 439 | DWORD SFMPQAPI WINAPI MpqCloseUpdatedArchive(MPQHANDLE hMPQ, DWORD dwUnknown2); 440 | BOOL SFMPQAPI WINAPI MpqAddFileToArchive(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags); 441 | BOOL SFMPQAPI WINAPI MpqAddWaveToArchive(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwQuality); 442 | BOOL SFMPQAPI WINAPI MpqRenameFile(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName); 443 | BOOL SFMPQAPI WINAPI MpqDeleteFile(MPQHANDLE hMPQ, LPCSTR lpFileName); 444 | BOOL SFMPQAPI WINAPI MpqCompactArchive(MPQHANDLE hMPQ); 445 | 446 | // Extra archive editing functions 447 | MPQHANDLE SFMPQAPI WINAPI MpqOpenArchiveForUpdateEx(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive, DWORD dwBlockSize); 448 | BOOL SFMPQAPI WINAPI MpqAddFileToArchiveEx(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel); 449 | BOOL SFMPQAPI WINAPI MpqAddFileFromBufferEx(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel); 450 | BOOL SFMPQAPI WINAPI MpqAddFileFromBuffer(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags); 451 | BOOL SFMPQAPI WINAPI MpqAddWaveFromBuffer(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwQuality); 452 | BOOL SFMPQAPI WINAPI MpqRenameAndSetFileLocale(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName, LCID nOldLocale, LCID nNewLocale); 453 | BOOL SFMPQAPI WINAPI MpqDeleteFileWithLocale(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nLocale); 454 | BOOL SFMPQAPI WINAPI MpqSetFileLocale(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nOldLocale, LCID nNewLocale); 455 | 456 | // These functions do nothing. They are only provided for 457 | // compatibility with MPQ extractors that use storm. 458 | BOOL SFMPQAPI WINAPI SFileDestroy(); 459 | void SFMPQAPI WINAPI StormDestroy(); 460 | 461 | #ifdef __cplusplus 462 | }; // extern "C" 463 | #endif 464 | 465 | #endif 466 | 467 | -------------------------------------------------------------------------------- /SFmpqapi.odl: -------------------------------------------------------------------------------- 1 | // License information for this code is in license.txt 2 | 3 | [ uuid(CF183E40-8316-11d6-9E07-00A0C9199875), version(1.08), 4 | helpstring("ShadowFlare MPQ API Library v1.08")] 5 | 6 | library SFMPQAPI 7 | { 8 | #define WINAPI __stdcall 9 | #define HANDLE long 10 | #define MPQHANDLE HANDLE 11 | #define DWORD long 12 | #define LPDWORD DWORD * 13 | #define LCID DWORD 14 | #define PLONG LONG * 15 | #define LPVOID LPSTR 16 | #define BOOL boolean 17 | typedef struct _OVERLAPPED { 18 | DWORD Internal; 19 | DWORD InternalHigh; 20 | DWORD Offset; 21 | DWORD OffsetHigh; 22 | HANDLE hEvent; 23 | } OVERLAPPED; 24 | //#define LPOVERLAPPED OVERLAPPED * 25 | #define LPOVERLAPPED long 26 | typedef struct _SFMPQVERSION { 27 | WORD Major; 28 | WORD Minor; 29 | WORD Revision; 30 | WORD Subrevision; 31 | } SFMPQVERSION; 32 | typedef struct _FILELISTENTRY { 33 | DWORD dwFileExists; // Nonzero if this entry is used 34 | LCID lcLocale; // Locale ID of file 35 | DWORD dwCompressedSize; // Compressed size of file 36 | DWORD dwFullSize; // Uncompressed size of file 37 | DWORD dwFlags; // Flags for file 38 | char szFileName[260]; 39 | } FILELISTENTRY; 40 | 41 | //[uuid(CF183E43-8316-11d6-9E07-00A0C9199875)] 42 | [helpstring("General error codes")] 43 | typedef enum { 44 | MPQ_ERROR_MPQ_INVALID = 0x85200065, 45 | MPQ_ERROR_FILE_NOT_FOUND = 0x85200066, 46 | MPQ_ERROR_DISK_FULL = 0x85200068, 47 | MPQ_ERROR_HASH_TABLE_FULL = 0x85200069, 48 | MPQ_ERROR_ALREADY_EXISTS = 0x8520006A, 49 | MPQ_ERROR_BAD_OPEN_MODE = 0x8520006C, 50 | MPQ_ERROR_COMPACT_ERROR = 0x85300001, 51 | } Error_Constants; 52 | 53 | [helpstring("MpqOpenArchiveForUpdate flags")] 54 | typedef enum { 55 | MOAU_CREATE_NEW = 0x00, 56 | MOAU_CREATE_ALWAYS = 0x08, 57 | MOAU_OPEN_EXISTING = 0x04, 58 | MOAU_OPEN_ALWAYS = 0x20, 59 | MOAU_READ_ONLY = 0x10, 60 | MOAU_MAINTAIN_ATTRIBUTES=0x02, 61 | MOAU_MAINTAIN_LISTFILE =0x01, 62 | } MpqOpenArchiveForUpdate_Flags; 63 | 64 | [helpstring("MpqOpenArchiveForUpdateEx constants")] 65 | typedef enum { 66 | DEFAULT_BLOCK_SIZE = 3, 67 | USE_DEFAULT_BLOCK_SIZE = 0xFFFFFFFF, 68 | } MpqOpenArchiveForUpdateEx_Constants; 69 | 70 | [helpstring("MpqAddFileToArchive flags")] 71 | typedef enum { 72 | MAFA_EXISTS = 0x80000000, 73 | MAFA_UNKNOWN40000000 = 0x40000000, 74 | MAFA_MODCRYPTKEY = 0x00020000, 75 | MAFA_ENCRYPT = 0x00010000, 76 | MAFA_COMPRESS = 0x00000200, 77 | MAFA_COMPRESS2 = 0x00000100, 78 | MAFA_REPLACE_EXISTING =0x00000001, 79 | } MpqAddFileToArchive_Flags; 80 | 81 | [helpstring("MpqAddFileToArchiveEx compression flags")] 82 | typedef enum { 83 | MAFA_COMPRESS_STANDARD = 0x08, 84 | MAFA_COMPRESS_DEFLATE = 0x02, 85 | MAFA_COMPRESS_BZIP2 = 0x10, 86 | MAFA_COMPRESS_WAVE = 0x81, 87 | MAFA_COMPRESS_WAVE2 = 0x41, 88 | MAFA_COMPRESS_WAVECOMP1 = 0x80, 89 | MAFA_COMPRESS_WAVECOMP2 = 0x40, 90 | MAFA_COMPRESS_WAVECOMP3 = 0x01, 91 | } MpqAddFileToArchiveEx_Compression_Types; 92 | 93 | [helpstring("Deflate compression level constants")] 94 | typedef enum { 95 | Z_NO_COMPRESSION = 0, 96 | Z_BEST_SPEED = 1, 97 | Z_BEST_COMPRESSION = 9, 98 | Z_DEFAULT_COMPRESSION = (-1), 99 | } Deflate_Compress_Level; 100 | 101 | [helpstring("MpqAddWaveToArchive quality flags")] 102 | typedef enum { 103 | MAWA_QUALITY_HIGH = 1, 104 | MAWA_QUALITY_MEDIUM = 0, 105 | MAWA_QUALITY_LOW = 2, 106 | } MpqAddWaveToArchive_Quality; 107 | 108 | [helpstring("SFileGetFileInfo flags")] 109 | typedef enum { 110 | SFILE_INFO_BLOCK_SIZE = 0x01, 111 | SFILE_INFO_HASH_TABLE_SIZE =0x02, 112 | SFILE_INFO_NUM_FILES = 0x03, 113 | SFILE_INFO_TYPE = 0x04, 114 | SFILE_INFO_SIZE = 0x05, 115 | SFILE_INFO_COMPRESSED_SIZE =0x06, 116 | SFILE_INFO_FLAGS = 0x07, 117 | SFILE_INFO_PARENT = 0x08, 118 | SFILE_INFO_POSITION = 0x09, 119 | SFILE_INFO_LOCALEID = 0x0A, 120 | SFILE_INFO_PRIORITY = 0x0B, 121 | SFILE_INFO_HASH_INDEX = 0x0C, 122 | SFILE_INFO_BLOCK_INDEX = 0x0D, 123 | } SFileGetFileInfo_Flags; 124 | 125 | [helpstring("Handle type constants")] 126 | typedef enum { 127 | SFILE_TYPE_MPQ = 0x01, 128 | SFILE_TYPE_FILE =0x02, 129 | } Handle_Type_Constants; 130 | 131 | [helpstring("SFileListFiles flags")] 132 | typedef enum { 133 | SFILE_LIST_MEMORY_LIST =0x01, 134 | SFILE_LIST_ONLY_KNOWN =0x02, 135 | SFILE_LIST_ONLY_UNKNOWN =0x04, 136 | SFILE_LIST_FLAG_UNKNOWN =0x08, 137 | } SFileListFiles_Flags; 138 | 139 | [helpstring("SFileOpenArchive flags")] 140 | typedef enum { 141 | SFILE_OPEN_HARD_DISK_FILE =0x0000, 142 | SFILE_OPEN_CD_ROM_FILE = 0x0001, 143 | SFILE_OPEN_ALLOW_WRITE = 0x8000, 144 | } SFileOpenArchive_Flags; 145 | 146 | [helpstring("SFileOpenFileEx flags")] 147 | typedef enum { 148 | SFILE_SEARCH_CURRENT_ONLY =0x00, 149 | SFILE_SEARCH_ALL_OPEN = 0x01 150 | } SFileOpenFileEx_Flags; 151 | 152 | [helpstring("Other misc. flags and constants")] 153 | typedef enum { 154 | INVALID_HANDLE_VALUE = 0xFFFFFFFF, 155 | } Other; 156 | 157 | 158 | [helpstring("SFileSetFilePointer move methods")] 159 | typedef enum { 160 | FILE_BEGIN = 0, 161 | FILE_CURRENT = 1, 162 | FILE_END = 2 163 | } SFileSetFilePointer_Move_Methods; 164 | 165 | [helpstring("Windows defined error codes")] 166 | typedef enum { 167 | ERROR_SUCCESS = 0, 168 | NO_ERROR = 0, 169 | ERROR_FILE_NOT_FOUND = 2, 170 | ERROR_OUTOFMEMORY = 14, 171 | ERROR_INVALID_PARAMETER = 87, 172 | ERROR_DISK_FULL = 112, 173 | ERROR_ALREADY_EXISTS = 183, 174 | ERROR_FILE_INVALID = 1006, 175 | ERROR_UNKNOWN_PROPERTY = 1608 176 | } WinErrors; 177 | 178 | [dllname("sfmpq.dll")] 179 | 180 | [helpstring("Version and other misc. functions")] 181 | module SFMpq 182 | { 183 | [entry("MpqInitialize"),helpstring("MpqInitialize does nothing; it is only provided for compatibility with MPQ archivers that use lmpqapi.")] 184 | BOOL WINAPI MpqInitialize(); 185 | [entry("MpqGetVersionString"),helpstring("")] 186 | LPCSTR WINAPI MpqGetVersionString(); 187 | [entry("MpqGetVersion"),helpstring("")] 188 | float WINAPI MpqGetVersion(); 189 | [entry("SFMpqDestroy"),helpstring("This no longer needs to be called; it is only provided for compatibility with older versions")] 190 | void WINAPI SFMpqDestroy(); 191 | [entry("AboutSFMpq"),helpstring("Displays an about page in a web browser (this has only been tested in Internet Explorer)")] 192 | void WINAPI AboutSFMpq(); 193 | [entry("SFMpqGetVersionString"),helpstring("")] 194 | LPCSTR WINAPI SFMpqGetVersionString(); 195 | [entry("SFMpqGetVersionString2"),helpstring("SFMpqGetVersionString2's return value is the required length of the buffer plus the terminating null, so use SFMpqGetVersionString2(0, 0) to get the length.")] 196 | DWORD WINAPI SFMpqGetVersionString2(LPCSTR lpBuffer, DWORD dwBufferLength); 197 | [entry("SFMpqGetVersion"),helpstring("")] 198 | SFMPQVERSION WINAPI SFMpqGetVersion(); 199 | }; 200 | 201 | [helpstring("Storm SFile emulated functions")] 202 | module SFile 203 | { 204 | [entry("SFileOpenArchive"),helpstring("")] 205 | BOOL WINAPI SFileOpenArchive(LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ); 206 | [entry("SFileCloseArchive"),helpstring("")] 207 | BOOL WINAPI SFileCloseArchive(MPQHANDLE hMPQ); 208 | [entry("SFileOpenFileAsArchive"),helpstring("")] 209 | BOOL WINAPI SFileOpenFileAsArchive(MPQHANDLE hSourceMPQ, LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ); 210 | [entry("SFileGetArchiveName"),helpstring("")] 211 | BOOL WINAPI SFileGetArchiveName(MPQHANDLE hMPQ, LPCSTR lpBuffer, DWORD dwBufferLength); 212 | [entry("SFileOpenFile"),helpstring("")] 213 | BOOL WINAPI SFileOpenFile(LPCSTR lpFileName, MPQHANDLE *hFile); 214 | [entry("SFileOpenFileEx"),helpstring("")] 215 | BOOL WINAPI SFileOpenFileEx(MPQHANDLE hMPQ, LPCSTR lpFileName, DWORD dwSearchScope, MPQHANDLE *hFile); 216 | [entry("SFileCloseFile"),helpstring("")] 217 | BOOL WINAPI SFileCloseFile(MPQHANDLE hFile); 218 | [entry("SFileGetFileSize"),helpstring("")] 219 | DWORD WINAPI SFileGetFileSize(MPQHANDLE hFile, LPDWORD lpFileSizeHigh); 220 | [entry("SFileGetFileArchive"),helpstring("")] 221 | BOOL WINAPI SFileGetFileArchive(MPQHANDLE hFile, MPQHANDLE *hMPQ); 222 | [entry("SFileGetFileName"),helpstring("")] 223 | BOOL WINAPI SFileGetFileName(MPQHANDLE hFile, LPCSTR lpBuffer, DWORD dwBufferLength); 224 | [entry("SFileSetFilePointer"),helpstring("")] 225 | DWORD WINAPI SFileSetFilePointer(MPQHANDLE hFile, long lDistanceToMove, PLONG lplDistanceToMoveHigh, DWORD dwMoveMethod); 226 | [entry("SFileReadFile"),helpstring("")] 227 | BOOL WINAPI SFileReadFile(MPQHANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped); 228 | [entry("SFileReadFile"),helpstring("")] 229 | BOOL WINAPI SFileReadFileB(MPQHANDLE hFile,byte *lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped); 230 | [entry("SFileSetLocale"),helpstring("")] 231 | LCID WINAPI SFileSetLocale(LCID nNewLocale); 232 | [entry("SFileGetBasePath"),helpstring("")] 233 | BOOL WINAPI SFileGetBasePath(LPCSTR lpBuffer, DWORD dwBufferLength); 234 | [entry("SFileSetBasePath"),helpstring("")] 235 | BOOL WINAPI SFileSetBasePath(LPCSTR lpNewBasePath); 236 | [entry("SFileGetFileInfo"),helpstring("")] 237 | DWORD WINAPI SFileGetFileInfo(MPQHANDLE hFile, DWORD dwInfoType); 238 | [entry("SFileSetArchivePriority"),helpstring("")] 239 | BOOL WINAPI SFileSetArchivePriority(MPQHANDLE hMPQ, DWORD dwPriority); 240 | [entry("SFileFindMpqHeader"),helpstring("")] 241 | DWORD WINAPI SFileFindMpqHeader(HANDLE hFile); 242 | [entry("SFileListFiles"),helpstring("")] 243 | BOOL WINAPI SFileListFiles(MPQHANDLE hMPQ, LPCSTR lpFileLists, FILELISTENTRY *lpListBuffer, DWORD dwFlags); 244 | [entry("SFileDestroy"),helpstring("")] 245 | BOOL WINAPI SFileDestroy(); 246 | [entry("StormDestroy"),helpstring("")] 247 | void WINAPI StormDestroy(); 248 | }; 249 | 250 | [helpstring("MPQ archive creation and editing functions")] 251 | module MPQ 252 | { 253 | [entry("MpqOpenArchiveForUpdate"),helpstring("")] 254 | MPQHANDLE WINAPI MpqOpenArchiveForUpdate(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive); 255 | [entry("MpqCloseUpdatedArchive"),helpstring("")] 256 | DWORD WINAPI MpqCloseUpdatedArchive(MPQHANDLE hMPQ, DWORD dwUnknown2); 257 | [entry("MpqAddFileToArchive"),helpstring("")] 258 | BOOL WINAPI MpqAddFileToArchive(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags); 259 | [entry("MpqAddWaveToArchive"),helpstring("")] 260 | BOOL WINAPI MpqAddWaveToArchive(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwQuality); 261 | [entry("MpqRenameFile"),helpstring("")] 262 | BOOL WINAPI MpqRenameFile(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName); 263 | [entry("MpqDeleteFile"),helpstring("")] 264 | BOOL WINAPI MpqDeleteFile(MPQHANDLE hMPQ, LPCSTR lpFileName); 265 | [entry("MpqCompactArchive"),helpstring("")] 266 | BOOL WINAPI MpqCompactArchive(MPQHANDLE hMPQ); 267 | [entry("MpqOpenArchiveForUpdateEx"),helpstring("")] 268 | MPQHANDLE WINAPI MpqOpenArchiveForUpdateEx(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive, DWORD dwBlockSize); 269 | [entry("MpqAddFileToArchiveEx"),helpstring("")] 270 | BOOL WINAPI MpqAddFileToArchiveEx(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel); 271 | [entry("MpqAddFileFromBufferEx"),helpstring("")] 272 | BOOL WINAPI MpqAddFileFromBufferEx(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel); 273 | [entry("MpqAddFileFromBufferEx"),helpstring("")] 274 | BOOL WINAPI MpqAddFileFromBufferExB(MPQHANDLE hMPQ, byte *lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel); 275 | [entry("MpqAddFileFromBuffer"),helpstring("")] 276 | BOOL WINAPI MpqAddFileFromBuffer(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags); 277 | [entry("MpqAddFileFromBuffer"),helpstring("")] 278 | BOOL WINAPI MpqAddFileFromBufferB(MPQHANDLE hMPQ, byte *lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags); 279 | [entry("MpqAddWaveFromBuffer"),helpstring("")] 280 | BOOL WINAPI MpqAddWaveFromBuffer(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwQuality); 281 | [entry("MpqAddWaveFromBuffer"),helpstring("")] 282 | BOOL WINAPI MpqAddWaveFromBufferB(MPQHANDLE hMPQ, byte *lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwQuality); 283 | [entry("MpqRenameAndSetFileLocale"),helpstring("")] 284 | BOOL WINAPI MpqRenameAndSetFileLocale(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName, LCID nOldLocale, LCID nNewLocale); 285 | [entry("MpqDeleteFileWithLocale"),helpstring("")] 286 | BOOL WINAPI MpqDeleteFileWithLocale(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nLocale); 287 | [entry("MpqSetFileLocale"),helpstring("")] 288 | BOOL WINAPI MpqSetFileLocale(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nOldLocale, LCID nNewLocale); 289 | }; 290 | 291 | [dllname("kernel32.dll")] 292 | 293 | module LastError 294 | { 295 | [entry("GetLastError"),helpstring("")] 296 | DWORD WINAPI GetLastError(); 297 | }; 298 | }; 299 | 300 | -------------------------------------------------------------------------------- /SFmpqapi.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShadowFlare/SFmpqapi/89eb0ac4c4ed931e796ceecd6287b57170cf9f98/SFmpqapi.rc -------------------------------------------------------------------------------- /SFmpqapi.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SFmpqapi", "SFmpqapi.vcproj", "{D677FDD7-F14A-403F-8D59-C75D1825260C}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SFmpqlib", "SFmpqlib.vcproj", "{2AB3EE05-94F1-433F-A9CF-F7E01220445D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Beta release|Win32 = Beta release|Win32 11 | Debug|Win32 = Debug|Win32 12 | Release|Win32 = Release|Win32 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {D677FDD7-F14A-403F-8D59-C75D1825260C}.Beta release|Win32.ActiveCfg = Beta release|Win32 16 | {D677FDD7-F14A-403F-8D59-C75D1825260C}.Beta release|Win32.Build.0 = Beta release|Win32 17 | {D677FDD7-F14A-403F-8D59-C75D1825260C}.Debug|Win32.ActiveCfg = Debug|Win32 18 | {D677FDD7-F14A-403F-8D59-C75D1825260C}.Debug|Win32.Build.0 = Debug|Win32 19 | {D677FDD7-F14A-403F-8D59-C75D1825260C}.Release|Win32.ActiveCfg = Release|Win32 20 | {D677FDD7-F14A-403F-8D59-C75D1825260C}.Release|Win32.Build.0 = Release|Win32 21 | {2AB3EE05-94F1-433F-A9CF-F7E01220445D}.Beta release|Win32.ActiveCfg = Release|Win32 22 | {2AB3EE05-94F1-433F-A9CF-F7E01220445D}.Beta release|Win32.Build.0 = Release|Win32 23 | {2AB3EE05-94F1-433F-A9CF-F7E01220445D}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {2AB3EE05-94F1-433F-A9CF-F7E01220445D}.Debug|Win32.Build.0 = Debug|Win32 25 | {2AB3EE05-94F1-433F-A9CF-F7E01220445D}.Release|Win32.ActiveCfg = Release|Win32 26 | {2AB3EE05-94F1-433F-A9CF-F7E01220445D}.Release|Win32.Build.0 = Release|Win32 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SFmpqapiVB.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\froman Times New Roman;}} 2 | \viewkind4\uc1\pard\b\f0\fs36 SFmpqapi for Visual Basic\b0\f1\fs20\par 3 | \f0\par 4 | When using SFileReadFile, create a byte array, resize the byte array according to the amount of data you want to read, and pass the array to the function by putting (0) after the name of the variable containing the byte array.\par 5 | \par 6 | For any optional parameters you are not using, for most functions you should use ByVal 0& for the parameter. This should work most or all of the time, but if it doesn't, just use the parameter how you normally would.\par 7 | } 8 | -------------------------------------------------------------------------------- /SFmpqapi_no-lib.cpp: -------------------------------------------------------------------------------- 1 | /* License information for this code is in license.txt */ 2 | 3 | // Code for loading SFmpqapi at run-time 4 | 5 | // Comment out the next line to load SFmpqapi at the 6 | // start of your program, rather that when it is first 7 | // used. 8 | #define SFMPQAPI_DELAY_LOAD 9 | 10 | #include "SFmpqapi_no-lib.h" 11 | 12 | struct SFMPQAPI_DELAY_LOADER { 13 | #ifndef SFMPQAPI_DELAY_LOAD 14 | SFMPQAPI_DELAY_LOADER(); 15 | #endif 16 | ~SFMPQAPI_DELAY_LOADER(); 17 | } SFMpqApi_Delay_Loader; 18 | 19 | HINSTANCE hSFMpq = 0; 20 | 21 | void LoadSFMpqDll(); 22 | 23 | void LoadSFMpqDll() 24 | { 25 | if (!hSFMpq) hSFMpq = LoadLibrary("SFmpq.dll"); 26 | } 27 | 28 | BOOL WINAPI MpqInitialize_stub() 29 | { 30 | LoadSFMpqDll(); 31 | if (hSFMpq) { 32 | *(FARPROC *)&MpqInitialize = GetProcAddress(hSFMpq,"MpqInitialize"); 33 | if (MpqInitialize) return MpqInitialize(); 34 | } 35 | return FALSE; 36 | } 37 | 38 | LPCSTR WINAPI MpqGetVersionString_stub() 39 | { 40 | LoadSFMpqDll(); 41 | if (hSFMpq) { 42 | *(FARPROC *)&MpqGetVersionString = GetProcAddress(hSFMpq,"MpqGetVersionString"); 43 | if (MpqGetVersionString) return MpqGetVersionString(); 44 | } 45 | return 0; 46 | } 47 | 48 | float WINAPI MpqGetVersion_stub() 49 | { 50 | LoadSFMpqDll(); 51 | if (hSFMpq) { 52 | *(FARPROC *)&MpqGetVersion = GetProcAddress(hSFMpq,"MpqGetVersion"); 53 | if (MpqGetVersion) return MpqGetVersion(); 54 | } 55 | return 0; 56 | } 57 | 58 | void WINAPI SFMpqDestroy_stub() 59 | { 60 | LoadSFMpqDll(); 61 | if (hSFMpq) { 62 | *(FARPROC *)&SFMpqDestroy = GetProcAddress(hSFMpq,"SFMpqDestroy"); 63 | if (SFMpqDestroy) SFMpqDestroy(); 64 | } 65 | } 66 | 67 | void WINAPI AboutSFMpq_stub() 68 | { 69 | LoadSFMpqDll(); 70 | if (hSFMpq) { 71 | *(FARPROC *)&AboutSFMpq = GetProcAddress(hSFMpq,"AboutSFMpq"); 72 | if (AboutSFMpq) AboutSFMpq(); 73 | } 74 | } 75 | 76 | LPCSTR WINAPI SFMpqGetVersionString_stub() 77 | { 78 | LoadSFMpqDll(); 79 | if (hSFMpq) { 80 | *(FARPROC *)&SFMpqGetVersionString = GetProcAddress(hSFMpq,"SFMpqGetVersionString"); 81 | if (SFMpqGetVersionString) return SFMpqGetVersionString(); 82 | } 83 | return 0; 84 | } 85 | 86 | DWORD WINAPI SFMpqGetVersionString2_stub(LPCSTR lpBuffer, DWORD dwBufferLength) 87 | { 88 | LoadSFMpqDll(); 89 | if (hSFMpq) { 90 | *(FARPROC *)&SFMpqGetVersionString2 = GetProcAddress(hSFMpq,"SFMpqGetVersionString2"); 91 | if (SFMpqGetVersionString2) return SFMpqGetVersionString2(lpBuffer,dwBufferLength); 92 | } 93 | return 0; 94 | } 95 | 96 | SFMPQVERSION WINAPI SFMpqGetVersion_stub() 97 | { 98 | LoadSFMpqDll(); 99 | if (hSFMpq) { 100 | *(FARPROC *)&SFMpqGetVersion = GetProcAddress(hSFMpq,"SFMpqGetVersion"); 101 | if (SFMpqGetVersion) return SFMpqGetVersion(); 102 | } 103 | SFMPQVERSION NoVersionData = {0,0,0,0}; 104 | return NoVersionData; 105 | } 106 | 107 | BOOL WINAPI SFileOpenArchive_stub(LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ) 108 | { 109 | LoadSFMpqDll(); 110 | if (hSFMpq) { 111 | *(FARPROC *)&SFileOpenArchive = GetProcAddress(hSFMpq,"SFileOpenArchive"); 112 | if (SFileOpenArchive) return SFileOpenArchive(lpFileName,dwPriority,dwFlags,hMPQ); 113 | } 114 | return FALSE; 115 | } 116 | 117 | BOOL WINAPI SFileCloseArchive_stub(MPQHANDLE hMPQ) 118 | { 119 | LoadSFMpqDll(); 120 | if (hSFMpq) { 121 | *(FARPROC *)&SFileCloseArchive = GetProcAddress(hSFMpq,"SFileCloseArchive"); 122 | if (SFileCloseArchive) return SFileCloseArchive(hMPQ); 123 | } 124 | return FALSE; 125 | } 126 | 127 | BOOL WINAPI SFileOpenFileAsArchive_stub(MPQHANDLE hSourceMPQ, LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ) 128 | { 129 | LoadSFMpqDll(); 130 | if (hSFMpq) { 131 | *(FARPROC *)&SFileOpenFileAsArchive = GetProcAddress(hSFMpq,"SFileOpenFileAsArchive"); 132 | if (SFileOpenFileAsArchive) return SFileOpenFileAsArchive(hSourceMPQ,lpFileName,dwPriority,dwFlags,hMPQ); 133 | } 134 | return FALSE; 135 | } 136 | 137 | BOOL WINAPI SFileGetArchiveName_stub(MPQHANDLE hMPQ, LPCSTR lpBuffer, DWORD dwBufferLength) 138 | { 139 | LoadSFMpqDll(); 140 | if (hSFMpq) { 141 | *(FARPROC *)&SFileGetArchiveName = GetProcAddress(hSFMpq,"SFileGetArchiveName"); 142 | if (SFileGetArchiveName) return SFileGetArchiveName(hMPQ,lpBuffer,dwBufferLength); 143 | } 144 | return FALSE; 145 | } 146 | 147 | BOOL WINAPI SFileOpenFile_stub(LPCSTR lpFileName, MPQHANDLE *hFile) 148 | { 149 | LoadSFMpqDll(); 150 | if (hSFMpq) { 151 | *(FARPROC *)&SFileOpenFile = GetProcAddress(hSFMpq,"SFileOpenFile"); 152 | if (SFileOpenFile) return SFileOpenFile(lpFileName,hFile); 153 | } 154 | return FALSE; 155 | } 156 | 157 | BOOL WINAPI SFileOpenFileEx_stub(MPQHANDLE hMPQ, LPCSTR lpFileName, DWORD dwSearchScope, MPQHANDLE *hFile) 158 | { 159 | LoadSFMpqDll(); 160 | if (hSFMpq) { 161 | *(FARPROC *)&SFileOpenFileEx = GetProcAddress(hSFMpq,"SFileOpenFileEx"); 162 | if (SFileOpenFileEx) return SFileOpenFileEx(hMPQ,lpFileName,dwSearchScope,hFile); 163 | } 164 | return FALSE; 165 | } 166 | 167 | BOOL WINAPI SFileCloseFile_stub(MPQHANDLE hFile) 168 | { 169 | LoadSFMpqDll(); 170 | if (hSFMpq) { 171 | *(FARPROC *)&SFileCloseFile = GetProcAddress(hSFMpq,"SFileCloseFile"); 172 | if (SFileCloseFile) return SFileCloseFile(hFile); 173 | } 174 | return FALSE; 175 | } 176 | 177 | DWORD WINAPI SFileGetFileSize_stub(MPQHANDLE hFile, LPDWORD lpFileSizeHigh) 178 | { 179 | LoadSFMpqDll(); 180 | if (hSFMpq) { 181 | *(FARPROC *)&SFileGetFileSize = GetProcAddress(hSFMpq,"SFileGetFileSize"); 182 | if (SFileGetFileSize) return SFileGetFileSize(hFile,lpFileSizeHigh); 183 | } 184 | return (DWORD)-1; 185 | } 186 | 187 | BOOL WINAPI SFileGetFileArchive_stub(MPQHANDLE hFile, MPQHANDLE *hMPQ) 188 | { 189 | LoadSFMpqDll(); 190 | if (hSFMpq) { 191 | *(FARPROC *)&SFileGetFileArchive = GetProcAddress(hSFMpq,"SFileGetFileArchive"); 192 | if (SFileGetFileArchive) return SFileGetFileArchive(hFile,hMPQ); 193 | } 194 | return FALSE; 195 | } 196 | 197 | BOOL WINAPI SFileGetFileName_stub(MPQHANDLE hFile, LPCSTR lpBuffer, DWORD dwBufferLength) 198 | { 199 | LoadSFMpqDll(); 200 | if (hSFMpq) { 201 | *(FARPROC *)&SFileGetFileName = GetProcAddress(hSFMpq,"SFileGetFileName"); 202 | if (SFileGetFileName) return SFileGetFileName(hFile,lpBuffer,dwBufferLength); 203 | } 204 | return FALSE; 205 | } 206 | 207 | DWORD WINAPI SFileSetFilePointer_stub(MPQHANDLE hFile, long lDistanceToMove, PLONG lplDistanceToMoveHigh, DWORD dwMoveMethod) 208 | { 209 | LoadSFMpqDll(); 210 | if (hSFMpq) { 211 | *(FARPROC *)&SFileSetFilePointer = GetProcAddress(hSFMpq,"SFileSetFilePointer"); 212 | if (SFileSetFilePointer) return SFileSetFilePointer(hFile,lDistanceToMove,lplDistanceToMoveHigh,dwMoveMethod); 213 | } 214 | return (DWORD)-1; 215 | } 216 | 217 | BOOL WINAPI SFileReadFile_stub(MPQHANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped) 218 | { 219 | LoadSFMpqDll(); 220 | if (hSFMpq) { 221 | *(FARPROC *)&SFileReadFile = GetProcAddress(hSFMpq,"SFileReadFile"); 222 | if (SFileReadFile) return SFileReadFile(hFile,lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,lpOverlapped); 223 | } 224 | return FALSE; 225 | } 226 | 227 | LCID WINAPI SFileSetLocale_stub(LCID nNewLocale) 228 | { 229 | LoadSFMpqDll(); 230 | if (hSFMpq) { 231 | *(FARPROC *)&SFileSetLocale = GetProcAddress(hSFMpq,"SFileSetLocale"); 232 | if (SFileSetLocale) return SFileSetLocale(nNewLocale); 233 | } 234 | return 0; 235 | } 236 | 237 | BOOL WINAPI SFileGetBasePath_stub(LPCSTR lpBuffer, DWORD dwBufferLength) 238 | { 239 | LoadSFMpqDll(); 240 | if (hSFMpq) { 241 | *(FARPROC *)&SFileGetBasePath = GetProcAddress(hSFMpq,"SFileGetBasePath"); 242 | if (SFileGetBasePath) return SFileGetBasePath(lpBuffer,dwBufferLength); 243 | } 244 | return FALSE; 245 | } 246 | 247 | BOOL WINAPI SFileSetBasePath_stub(LPCSTR lpNewBasePath) 248 | { 249 | LoadSFMpqDll(); 250 | if (hSFMpq) { 251 | *(FARPROC *)&SFileSetBasePath = GetProcAddress(hSFMpq,"SFileSetBasePath"); 252 | if (SFileSetBasePath) return SFileSetBasePath(lpNewBasePath); 253 | } 254 | return FALSE; 255 | } 256 | 257 | DWORD WINAPI SFileGetFileInfo_stub(MPQHANDLE hFile, DWORD dwInfoType) 258 | { 259 | LoadSFMpqDll(); 260 | if (hSFMpq) { 261 | *(FARPROC *)&SFileGetFileInfo = GetProcAddress(hSFMpq,"SFileGetFileInfo"); 262 | if (SFileGetFileInfo) return SFileGetFileInfo(hFile,dwInfoType); 263 | } 264 | return (DWORD)-1; 265 | } 266 | 267 | BOOL WINAPI SFileSetArchivePriority_stub(MPQHANDLE hMPQ, DWORD dwPriority) 268 | { 269 | LoadSFMpqDll(); 270 | if (hSFMpq) { 271 | *(FARPROC *)&SFileSetArchivePriority = GetProcAddress(hSFMpq,"SFileSetArchivePriority"); 272 | if (SFileSetArchivePriority) return SFileSetArchivePriority(hMPQ,dwPriority); 273 | } 274 | return FALSE; 275 | } 276 | 277 | DWORD WINAPI SFileFindMpqHeader_stub(HANDLE hFile) 278 | { 279 | LoadSFMpqDll(); 280 | if (hSFMpq) { 281 | *(FARPROC *)&SFileFindMpqHeader = GetProcAddress(hSFMpq,"SFileFindMpqHeader"); 282 | if (SFileFindMpqHeader) return SFileFindMpqHeader(hFile); 283 | } 284 | return (DWORD)-1; 285 | } 286 | 287 | BOOL WINAPI SFileListFiles_stub(MPQHANDLE hMPQ, LPCSTR lpFileLists, FILELISTENTRY *lpListBuffer, DWORD dwFlags) 288 | { 289 | LoadSFMpqDll(); 290 | if (hSFMpq) { 291 | *(FARPROC *)&SFileListFiles = GetProcAddress(hSFMpq,"SFileListFiles"); 292 | if (SFileListFiles) return SFileListFiles(hMPQ,lpFileLists,lpListBuffer,dwFlags); 293 | } 294 | return FALSE; 295 | } 296 | 297 | MPQHANDLE WINAPI MpqOpenArchiveForUpdate_stub(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive) 298 | { 299 | LoadSFMpqDll(); 300 | if (hSFMpq) { 301 | *(FARPROC *)&MpqOpenArchiveForUpdate = GetProcAddress(hSFMpq,"MpqOpenArchiveForUpdate"); 302 | if (MpqOpenArchiveForUpdate) return MpqOpenArchiveForUpdate(lpFileName,dwFlags,dwMaximumFilesInArchive); 303 | } 304 | return INVALID_HANDLE_VALUE; 305 | } 306 | 307 | DWORD WINAPI MpqCloseUpdatedArchive_stub(MPQHANDLE hMPQ, DWORD dwUnknown2) 308 | { 309 | LoadSFMpqDll(); 310 | if (hSFMpq) { 311 | *(FARPROC *)&MpqCloseUpdatedArchive = GetProcAddress(hSFMpq,"MpqCloseUpdatedArchive"); 312 | if (MpqCloseUpdatedArchive) return MpqCloseUpdatedArchive(hMPQ,dwUnknown2); 313 | } 314 | return 0; 315 | } 316 | 317 | BOOL WINAPI MpqAddFileToArchive_stub(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags) 318 | { 319 | LoadSFMpqDll(); 320 | if (hSFMpq) { 321 | *(FARPROC *)&MpqAddFileToArchive = GetProcAddress(hSFMpq,"MpqAddFileToArchive"); 322 | if (MpqAddFileToArchive) return MpqAddFileToArchive(hMPQ,lpSourceFileName,lpDestFileName,dwFlags); 323 | } 324 | return FALSE; 325 | } 326 | 327 | BOOL WINAPI MpqAddWaveToArchive_stub(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwQuality) 328 | { 329 | LoadSFMpqDll(); 330 | if (hSFMpq) { 331 | *(FARPROC *)&MpqAddWaveToArchive = GetProcAddress(hSFMpq,"MpqAddWaveToArchive"); 332 | if (MpqAddWaveToArchive) return MpqAddWaveToArchive(hMPQ,lpSourceFileName,lpDestFileName,dwFlags,dwQuality); 333 | } 334 | return FALSE; 335 | } 336 | 337 | BOOL WINAPI MpqRenameFile_stub(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName) 338 | { 339 | LoadSFMpqDll(); 340 | if (hSFMpq) { 341 | *(FARPROC *)&MpqRenameFile = GetProcAddress(hSFMpq,"MpqRenameFile"); 342 | if (MpqRenameFile) return MpqRenameFile(hMPQ,lpcOldFileName,lpcNewFileName); 343 | } 344 | return FALSE; 345 | } 346 | 347 | BOOL WINAPI MpqDeleteFile_stub(MPQHANDLE hMPQ, LPCSTR lpFileName) 348 | { 349 | LoadSFMpqDll(); 350 | if (hSFMpq) { 351 | *(FARPROC *)&MpqDeleteFile = GetProcAddress(hSFMpq,"MpqDeleteFile"); 352 | if (MpqDeleteFile) return MpqDeleteFile(hMPQ,lpFileName); 353 | } 354 | return FALSE; 355 | } 356 | 357 | BOOL WINAPI MpqCompactArchive_stub(MPQHANDLE hMPQ) 358 | { 359 | LoadSFMpqDll(); 360 | if (hSFMpq) { 361 | *(FARPROC *)&MpqCompactArchive = GetProcAddress(hSFMpq,"MpqCompactArchive"); 362 | if (MpqCompactArchive) return MpqCompactArchive(hMPQ); 363 | } 364 | return FALSE; 365 | } 366 | 367 | MPQHANDLE WINAPI MpqOpenArchiveForUpdateEx_stub(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive, DWORD dwBlockSize) 368 | { 369 | LoadSFMpqDll(); 370 | if (hSFMpq) { 371 | *(FARPROC *)&MpqOpenArchiveForUpdateEx = GetProcAddress(hSFMpq,"MpqOpenArchiveForUpdateEx"); 372 | if (MpqOpenArchiveForUpdateEx) return MpqOpenArchiveForUpdateEx(lpFileName,dwFlags,dwMaximumFilesInArchive,dwBlockSize); 373 | } 374 | return INVALID_HANDLE_VALUE; 375 | } 376 | 377 | BOOL WINAPI MpqAddFileToArchiveEx_stub(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel) 378 | { 379 | LoadSFMpqDll(); 380 | if (hSFMpq) { 381 | *(FARPROC *)&MpqAddFileToArchiveEx = GetProcAddress(hSFMpq,"MpqAddFileToArchiveEx"); 382 | if (MpqAddFileToArchiveEx) return MpqAddFileToArchiveEx(hMPQ,lpSourceFileName,lpDestFileName,dwFlags,dwCompressionType,dwCompressLevel); 383 | } 384 | return FALSE; 385 | } 386 | 387 | BOOL WINAPI MpqAddFileFromBufferEx_stub(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel) 388 | { 389 | LoadSFMpqDll(); 390 | if (hSFMpq) { 391 | *(FARPROC *)&MpqAddFileFromBufferEx = GetProcAddress(hSFMpq,"MpqAddFileFromBufferEx"); 392 | if (MpqAddFileFromBufferEx) return MpqAddFileFromBufferEx(hMPQ,lpBuffer,dwLength,lpFileName,dwFlags,dwCompressionType,dwCompressLevel); 393 | } 394 | return FALSE; 395 | } 396 | 397 | BOOL WINAPI MpqAddFileFromBuffer_stub(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags) 398 | { 399 | LoadSFMpqDll(); 400 | if (hSFMpq) { 401 | *(FARPROC *)&MpqAddFileFromBuffer = GetProcAddress(hSFMpq,"MpqAddFileFromBuffer"); 402 | if (MpqAddFileFromBuffer) return MpqAddFileFromBuffer(hMPQ,lpBuffer,dwLength,lpFileName,dwFlags); 403 | } 404 | return FALSE; 405 | } 406 | 407 | BOOL WINAPI MpqAddWaveFromBuffer_stub(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwQuality) 408 | { 409 | LoadSFMpqDll(); 410 | if (hSFMpq) { 411 | *(FARPROC *)&MpqAddWaveFromBuffer = GetProcAddress(hSFMpq,"MpqAddWaveFromBuffer"); 412 | if (MpqAddWaveFromBuffer) return MpqAddWaveFromBuffer(hMPQ,lpBuffer,dwLength,lpFileName,dwFlags,dwQuality); 413 | } 414 | return FALSE; 415 | } 416 | 417 | BOOL WINAPI MpqRenameAndSetFileLocale_stub(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName, LCID nOldLocale, LCID nNewLocale) 418 | { 419 | LoadSFMpqDll(); 420 | if (hSFMpq) { 421 | *(FARPROC *)&MpqRenameAndSetFileLocale = GetProcAddress(hSFMpq,"MpqRenameAndSetFileLocale"); 422 | if (MpqRenameAndSetFileLocale) return MpqRenameAndSetFileLocale(hMPQ,lpcOldFileName,lpcNewFileName,nOldLocale,nNewLocale); 423 | } 424 | return FALSE; 425 | } 426 | 427 | BOOL WINAPI MpqDeleteFileWithLocale_stub(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nLocale) 428 | { 429 | LoadSFMpqDll(); 430 | if (hSFMpq) { 431 | *(FARPROC *)&MpqDeleteFileWithLocale = GetProcAddress(hSFMpq,"MpqDeleteFileWithLocale"); 432 | if (MpqDeleteFileWithLocale) return MpqDeleteFileWithLocale(hMPQ,lpFileName,nLocale); 433 | } 434 | return FALSE; 435 | } 436 | 437 | BOOL WINAPI MpqSetFileLocale_stub(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nOldLocale, LCID nNewLocale) 438 | { 439 | LoadSFMpqDll(); 440 | if (hSFMpq) { 441 | *(FARPROC *)&MpqSetFileLocale = GetProcAddress(hSFMpq,"MpqSetFileLocale"); 442 | if (MpqSetFileLocale) return MpqSetFileLocale(hMPQ,lpFileName,nOldLocale,nNewLocale); 443 | } 444 | return FALSE; 445 | } 446 | 447 | BOOL WINAPI SFileDestroy_stub() 448 | { 449 | LoadSFMpqDll(); 450 | if (hSFMpq) { 451 | *(FARPROC *)&SFileDestroy = GetProcAddress(hSFMpq,"SFileDestroy"); 452 | if (SFileDestroy) return SFileDestroy(); 453 | } 454 | return FALSE; 455 | } 456 | 457 | void WINAPI StormDestroy_stub() 458 | { 459 | LoadSFMpqDll(); 460 | if (hSFMpq) { 461 | *(FARPROC *)&StormDestroy = GetProcAddress(hSFMpq,"StormDestroy"); 462 | if (StormDestroy) StormDestroy(); 463 | } 464 | } 465 | 466 | BOOL (WINAPI* MpqInitialize)() = MpqInitialize_stub; 467 | 468 | LPCSTR (WINAPI* MpqGetVersionString)() = MpqGetVersionString_stub; 469 | float (WINAPI* MpqGetVersion)() = MpqGetVersion_stub; 470 | 471 | void (WINAPI* SFMpqDestroy)() = SFMpqDestroy_stub; 472 | 473 | void (WINAPI* AboutSFMpq)() = AboutSFMpq_stub; 474 | 475 | LPCSTR (WINAPI* SFMpqGetVersionString)() = SFMpqGetVersionString_stub; 476 | DWORD (WINAPI* SFMpqGetVersionString2)(LPCSTR lpBuffer, DWORD dwBufferLength) = SFMpqGetVersionString2_stub; 477 | SFMPQVERSION (WINAPI* SFMpqGetVersion)() = SFMpqGetVersion_stub; 478 | 479 | BOOL (WINAPI* SFileOpenArchive)(LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ) = SFileOpenArchive_stub; 480 | BOOL (WINAPI* SFileCloseArchive)(MPQHANDLE hMPQ) = SFileCloseArchive_stub; 481 | BOOL (WINAPI* SFileOpenFileAsArchive)(MPQHANDLE hSourceMPQ, LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ) = SFileOpenFileAsArchive_stub; 482 | BOOL (WINAPI* SFileGetArchiveName)(MPQHANDLE hMPQ, LPCSTR lpBuffer, DWORD dwBufferLength) = SFileGetArchiveName_stub; 483 | BOOL (WINAPI* SFileOpenFile)(LPCSTR lpFileName, MPQHANDLE *hFile) = SFileOpenFile_stub; 484 | BOOL (WINAPI* SFileOpenFileEx)(MPQHANDLE hMPQ, LPCSTR lpFileName, DWORD dwSearchScope, MPQHANDLE *hFile) = SFileOpenFileEx_stub; 485 | BOOL (WINAPI* SFileCloseFile)(MPQHANDLE hFile) = SFileCloseFile_stub; 486 | DWORD (WINAPI* SFileGetFileSize)(MPQHANDLE hFile, LPDWORD lpFileSizeHigh) = SFileGetFileSize_stub; 487 | BOOL (WINAPI* SFileGetFileArchive)(MPQHANDLE hFile, MPQHANDLE *hMPQ) = SFileGetFileArchive_stub; 488 | BOOL (WINAPI* SFileGetFileName)(MPQHANDLE hFile, LPCSTR lpBuffer, DWORD dwBufferLength) = SFileGetFileName_stub; 489 | DWORD (WINAPI* SFileSetFilePointer)(MPQHANDLE hFile, long lDistanceToMove, PLONG lplDistanceToMoveHigh, DWORD dwMoveMethod) = SFileSetFilePointer_stub; 490 | BOOL (WINAPI* SFileReadFile)(MPQHANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped) = SFileReadFile_stub; 491 | LCID (WINAPI* SFileSetLocale)(LCID nNewLocale) = SFileSetLocale_stub; 492 | BOOL (WINAPI* SFileGetBasePath)(LPCSTR lpBuffer, DWORD dwBufferLength) = SFileGetBasePath_stub; 493 | BOOL (WINAPI* SFileSetBasePath)(LPCSTR lpNewBasePath) = SFileSetBasePath_stub; 494 | 495 | DWORD (WINAPI* SFileGetFileInfo)(MPQHANDLE hFile, DWORD dwInfoType) = SFileGetFileInfo_stub; 496 | BOOL (WINAPI* SFileSetArchivePriority)(MPQHANDLE hMPQ, DWORD dwPriority) = SFileSetArchivePriority_stub; 497 | DWORD (WINAPI* SFileFindMpqHeader)(HANDLE hFile) = SFileFindMpqHeader_stub; 498 | BOOL (WINAPI* SFileListFiles)(MPQHANDLE hMPQ, LPCSTR lpFileLists, FILELISTENTRY *lpListBuffer, DWORD dwFlags) = SFileListFiles_stub; 499 | 500 | MPQHANDLE (WINAPI* MpqOpenArchiveForUpdate)(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive) = MpqOpenArchiveForUpdate_stub; 501 | DWORD (WINAPI* MpqCloseUpdatedArchive)(MPQHANDLE hMPQ, DWORD dwUnknown2) = MpqCloseUpdatedArchive_stub; 502 | BOOL (WINAPI* MpqAddFileToArchive)(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags) = MpqAddFileToArchive_stub; 503 | BOOL (WINAPI* MpqAddWaveToArchive)(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwQuality) = MpqAddWaveToArchive_stub; 504 | BOOL (WINAPI* MpqRenameFile)(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName) = MpqRenameFile_stub; 505 | BOOL (WINAPI* MpqDeleteFile)(MPQHANDLE hMPQ, LPCSTR lpFileName) = MpqDeleteFile_stub; 506 | BOOL (WINAPI* MpqCompactArchive)(MPQHANDLE hMPQ) = MpqCompactArchive_stub; 507 | 508 | MPQHANDLE (WINAPI* MpqOpenArchiveForUpdateEx)(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive, DWORD dwBlockSize) = MpqOpenArchiveForUpdateEx_stub; 509 | BOOL (WINAPI* MpqAddFileToArchiveEx)(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel) = MpqAddFileToArchiveEx_stub; 510 | BOOL (WINAPI* MpqAddFileFromBufferEx)(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel) = MpqAddFileFromBufferEx_stub; 511 | BOOL (WINAPI* MpqAddFileFromBuffer)(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags) = MpqAddFileFromBuffer_stub; 512 | BOOL (WINAPI* MpqAddWaveFromBuffer)(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwQuality) = MpqAddWaveFromBuffer_stub; 513 | BOOL (WINAPI* MpqRenameAndSetFileLocale)(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName, LCID nOldLocale, LCID nNewLocale) = MpqRenameAndSetFileLocale_stub; 514 | BOOL (WINAPI* MpqDeleteFileWithLocale)(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nLocale) = MpqDeleteFileWithLocale_stub; 515 | BOOL (WINAPI* MpqSetFileLocale)(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nOldLocale, LCID nNewLocale) = MpqSetFileLocale_stub; 516 | 517 | BOOL (WINAPI* SFileDestroy)() = SFileDestroy_stub; 518 | void (WINAPI* StormDestroy)() = StormDestroy_stub; 519 | 520 | #ifndef SFMPQAPI_DELAY_LOAD 521 | SFMPQAPI_DELAY_LOADER::SFMPQAPI_DELAY_LOADER() 522 | { 523 | LoadSFMpqDll(); 524 | } 525 | #endif 526 | 527 | SFMPQAPI_DELAY_LOADER::~SFMPQAPI_DELAY_LOADER() 528 | { 529 | MpqInitialize = 0; 530 | 531 | MpqGetVersionString = 0; 532 | MpqGetVersion = 0; 533 | 534 | AboutSFMpq = 0; 535 | 536 | SFMpqGetVersionString = 0; 537 | SFMpqGetVersionString2 = 0; 538 | SFMpqGetVersion = 0; 539 | 540 | SFileOpenArchive = 0; 541 | SFileCloseArchive = 0; 542 | SFileOpenFileAsArchive = 0; 543 | SFileGetArchiveName = 0; 544 | SFileOpenFile = 0; 545 | SFileOpenFileEx = 0; 546 | SFileCloseFile = 0; 547 | SFileGetFileSize = 0; 548 | SFileGetFileArchive = 0; 549 | SFileGetFileName = 0; 550 | SFileSetFilePointer = 0; 551 | SFileReadFile = 0; 552 | SFileSetLocale = 0; 553 | SFileGetBasePath = 0; 554 | SFileSetBasePath = 0; 555 | 556 | SFileGetFileInfo = 0; 557 | SFileSetArchivePriority = 0; 558 | SFileFindMpqHeader = 0; 559 | SFileListFiles = 0; 560 | 561 | MpqOpenArchiveForUpdate = 0; 562 | MpqCloseUpdatedArchive = 0; 563 | MpqAddFileToArchive = 0; 564 | MpqAddWaveToArchive = 0; 565 | MpqRenameFile = 0; 566 | MpqDeleteFile = 0; 567 | MpqCompactArchive = 0; 568 | 569 | MpqOpenArchiveForUpdateEx = 0; 570 | MpqAddFileToArchiveEx = 0; 571 | MpqAddFileFromBufferEx = 0; 572 | MpqAddFileFromBuffer = 0; 573 | MpqAddWaveFromBuffer = 0; 574 | MpqRenameAndSetFileLocale = 0; 575 | MpqDeleteFileWithLocale = 0; 576 | MpqSetFileLocale = 0; 577 | 578 | SFileDestroy = 0; 579 | StormDestroy = 0; 580 | 581 | if (hSFMpq==0) return; 582 | if (SFMpqDestroy!=0) SFMpqDestroy(); 583 | 584 | SFMpqDestroy = 0; 585 | 586 | FreeLibrary(hSFMpq); 587 | hSFMpq = 0; 588 | } 589 | 590 | long SFMpqCompareVersion() 591 | { 592 | SFMPQVERSION ExeVersion = {1,0,8,1}; 593 | SFMPQVERSION DllVersion = SFMpqGetVersion(); 594 | if (DllVersion.Major>ExeVersion.Major) return 1; 595 | else if (DllVersion.MajorExeVersion.Minor) return 1; 597 | else if (DllVersion.MinorExeVersion.Revision) return 1; 599 | else if (DllVersion.RevisionExeVersion.Subrevision) return 1; 601 | else if (DllVersion.Subrevision 133 | All rights reserved. 134 | 135 | Redistribution and use in source and binary forms, with or without 136 | modification, are permitted provided that the following conditions 137 | are met: 138 | 139 | 1. Redistributions of source code must retain the above copyright 140 | notice, this list of conditions and the following disclaimer. 141 | 2. Redistributions in binary form must reproduce the above copyright 142 | notice, this list of conditions and the following disclaimer in the 143 | documentation and/or other materials provided with the distribution. 144 | 145 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND 146 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 147 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 148 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 149 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 150 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 151 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 152 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 153 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 154 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 155 | SUCH DAMAGE. 156 | */ 157 | 158 | #ifndef SHADOWFLARE_MPQ_API_INCLUDED 159 | #define SHADOWFLARE_MPQ_API_INCLUDED 160 | 161 | #include 162 | 163 | #ifdef __cplusplus 164 | extern "C" { 165 | #endif 166 | 167 | typedef struct { 168 | WORD Major; 169 | WORD Minor; 170 | WORD Revision; 171 | WORD Subrevision; 172 | } SFMPQVERSION; 173 | 174 | // These no longer need to be called. They only provided for 175 | // compatibility with older versions of this code 176 | #define LoadSFMpq() 177 | #define FreeSFMpq() 178 | 179 | // MpqInitialize does nothing. It is only provided for 180 | // compatibility with MPQ archivers that use lmpqapi. 181 | extern BOOL (WINAPI* MpqInitialize)(); 182 | 183 | extern LPCSTR (WINAPI* MpqGetVersionString)(); 184 | extern float (WINAPI* MpqGetVersion)(); 185 | 186 | extern void (WINAPI* SFMpqDestroy)(); // This no longer needs to be called. It is only provided for compatibility with older versions 187 | 188 | extern void (WINAPI* AboutSFMpq)(); // Displays an about page in a web browser (this has only been tested in Internet Explorer). This is only for the dll version of SFmpq 189 | 190 | // SFMpqGetVersionString2's return value is the required length of the buffer plus 191 | // the terminating null, so use SFMpqGetVersionString2(0, 0); to get the length. 192 | extern LPCSTR (WINAPI* SFMpqGetVersionString)(); 193 | extern DWORD (WINAPI* SFMpqGetVersionString2)(LPCSTR lpBuffer, DWORD dwBufferLength); 194 | extern SFMPQVERSION (WINAPI* SFMpqGetVersion)(); 195 | 196 | // Returns 0 if the dll version is equal to the version your program was compiled 197 | // with, 1 if the dll is newer, -1 if the dll is older. 198 | long SFMpqCompareVersion(); 199 | 200 | // General error codes 201 | #define MPQ_ERROR_MPQ_INVALID 0x85200065 202 | #define MPQ_ERROR_FILE_NOT_FOUND 0x85200066 203 | #define MPQ_ERROR_DISK_FULL 0x85200068 //Physical write file to MPQ failed. Not sure of exact meaning 204 | #define MPQ_ERROR_HASH_TABLE_FULL 0x85200069 205 | #define MPQ_ERROR_ALREADY_EXISTS 0x8520006A 206 | #define MPQ_ERROR_BAD_OPEN_MODE 0x8520006C //When MOAU_READ_ONLY is used without MOAU_OPEN_EXISTING 207 | 208 | #define MPQ_ERROR_COMPACT_ERROR 0x85300001 209 | 210 | // MpqOpenArchiveForUpdate flags 211 | #define MOAU_CREATE_NEW 0x00 //If archive does not exist, it will be created. If it exists, the function will fail 212 | #define MOAU_CREATE_ALWAYS 0x08 //Will always create a new archive 213 | #define MOAU_OPEN_EXISTING 0x04 //If archive exists, it will be opened. If it does not exist, the function will fail 214 | #define MOAU_OPEN_ALWAYS 0x20 //If archive exists, it will be opened. If it does not exist, it will be created 215 | #define MOAU_READ_ONLY 0x10 //Must be used with MOAU_OPEN_EXISTING. Archive will be opened without write access 216 | #define MOAU_MAINTAIN_ATTRIBUTES 0x02 //Will be used in a future version to create the (attributes) file. Contact me about any information you may have about the format of this file 217 | #define MOAU_MAINTAIN_LISTFILE 0x01 //Creates and maintains a list of files in archive when they are added, replaced, or deleted 218 | 219 | // MpqOpenArchiveForUpdateEx constants 220 | #define DEFAULT_BLOCK_SIZE 3 // 512 << number = block size 221 | #define USE_DEFAULT_BLOCK_SIZE 0xFFFFFFFF // Use default block size that is defined internally 222 | 223 | // MpqAddFileToArchive flags 224 | #define MAFA_EXISTS 0x80000000 //This flag will be added if not present 225 | #define MAFA_UNKNOWN40000000 0x40000000 //Unknown flag 226 | #define MAFA_MODCRYPTKEY 0x00020000 //Used with MAFA_ENCRYPT. Uses an encryption key based on file position and size 227 | #define MAFA_ENCRYPT 0x00010000 //Encrypts the file. The file is still accessible when using this, so the use of this has depreciated 228 | #define MAFA_COMPRESS 0x00000200 //File is to be compressed when added. This is used for most of the compression methods 229 | #define MAFA_COMPRESS2 0x00000100 //File is compressed with standard compression only (was used in Diablo 1) 230 | #define MAFA_REPLACE_EXISTING 0x00000001 //If file already exists, it will be replaced 231 | 232 | // MpqAddFileToArchiveEx compression flags 233 | #define MAFA_COMPRESS_STANDARD 0x08 //Standard PKWare DCL compression 234 | #define MAFA_COMPRESS_DEFLATE 0x02 //ZLib's deflate compression 235 | #define MAFA_COMPRESS_BZIP2 0x10 //bzip2 compression 236 | #define MAFA_COMPRESS_WAVE 0x81 //Stereo wave compression 237 | #define MAFA_COMPRESS_WAVE2 0x41 //Mono wave compression 238 | 239 | // Flags for individual compression types used for wave compression 240 | #define MAFA_COMPRESS_WAVECOMP1 0x80 //Main compressor for stereo wave compression 241 | #define MAFA_COMPRESS_WAVECOMP2 0x40 //Main compressor for mono wave compression 242 | #define MAFA_COMPRESS_WAVECOMP3 0x01 //Secondary compressor for wave compression 243 | 244 | // ZLib deflate compression level constants (used with MpqAddFileToArchiveEx and MpqAddFileFromBufferEx) 245 | #define Z_NO_COMPRESSION 0 246 | #define Z_BEST_SPEED 1 247 | #define Z_BEST_COMPRESSION 9 248 | #define Z_DEFAULT_COMPRESSION (-1) //Default level is 6 with current ZLib version 249 | 250 | // MpqAddWaveToArchive quality flags 251 | #define MAWA_QUALITY_HIGH 1 //Higher compression, lower quality 252 | #define MAWA_QUALITY_MEDIUM 0 //Medium compression, medium quality 253 | #define MAWA_QUALITY_LOW 2 //Lower compression, higher quality 254 | 255 | // SFileGetFileInfo flags 256 | #define SFILE_INFO_BLOCK_SIZE 0x01 //Block size in MPQ 257 | #define SFILE_INFO_HASH_TABLE_SIZE 0x02 //Hash table size in MPQ 258 | #define SFILE_INFO_NUM_FILES 0x03 //Number of files in MPQ 259 | #define SFILE_INFO_TYPE 0x04 //Is MPQHANDLE a file or an MPQ? 260 | #define SFILE_INFO_SIZE 0x05 //Size of MPQ or uncompressed file 261 | #define SFILE_INFO_COMPRESSED_SIZE 0x06 //Size of compressed file 262 | #define SFILE_INFO_FLAGS 0x07 //File flags (compressed, etc.), file attributes if a file not in an archive 263 | #define SFILE_INFO_PARENT 0x08 //Handle of MPQ that file is in 264 | #define SFILE_INFO_POSITION 0x09 //Position of file pointer in files 265 | #define SFILE_INFO_LOCALEID 0x0A //Locale ID of file in MPQ 266 | #define SFILE_INFO_PRIORITY 0x0B //Priority of open MPQ 267 | #define SFILE_INFO_HASH_INDEX 0x0C //Hash index of file in MPQ 268 | #define SFILE_INFO_BLOCK_INDEX 0x0D //Block table index of file in MPQ 269 | 270 | // Return values of SFileGetFileInfo when SFILE_INFO_TYPE flag is used 271 | #define SFILE_TYPE_MPQ 0x01 272 | #define SFILE_TYPE_FILE 0x02 273 | 274 | // SFileListFiles flags 275 | #define SFILE_LIST_MEMORY_LIST 0x01 // Specifies that lpFilelists is a file list from memory, rather than being a list of file lists 276 | #define SFILE_LIST_ONLY_KNOWN 0x02 // Only list files that the function finds a name for 277 | #define SFILE_LIST_ONLY_UNKNOWN 0x04 // Only list files that the function does not find a name for 278 | #define SFILE_LIST_FLAG_UNKNOWN 0x08 // Use without SFILE_LIST_ONLY_KNOWN or SFILE_LIST_FLAG_UNKNOWN to list all files, but will set dwFileExists to 3 if file's name is not found 279 | 280 | // SFileOpenArchive flags 281 | #define SFILE_OPEN_HARD_DISK_FILE 0x0000 //Open archive without regard to the drive type it resides on 282 | #define SFILE_OPEN_CD_ROM_FILE 0x0001 //Open the archive only if it is on a CD-ROM 283 | #define SFILE_OPEN_ALLOW_WRITE 0x8000 //Open file with write access 284 | 285 | // SFileOpenFileEx search scopes 286 | #define SFILE_SEARCH_CURRENT_ONLY 0x00 //Used with SFileOpenFileEx; only the archive with the handle specified will be searched for the file 287 | #define SFILE_SEARCH_ALL_OPEN 0x01 //SFileOpenFileEx will look through all open archives for the file. This flag also allows files outside the archive to be used 288 | 289 | typedef HANDLE MPQHANDLE; 290 | 291 | struct FILELISTENTRY { 292 | DWORD dwFileExists; // Nonzero if this entry is used 293 | LCID lcLocale; // Locale ID of file 294 | DWORD dwCompressedSize; // Compressed size of file 295 | DWORD dwFullSize; // Uncompressed size of file 296 | DWORD dwFlags; // Flags for file 297 | char szFileName[260]; 298 | }; 299 | 300 | struct MPQARCHIVE; 301 | struct MPQFILE; 302 | struct MPQHEADER; 303 | struct BLOCKTABLEENTRY; 304 | struct HASHTABLEENTRY; 305 | 306 | struct MPQHEADER { 307 | DWORD dwMPQID; //"MPQ\x1A" for mpq's, "BN3\x1A" for bncache.dat 308 | DWORD dwHeaderSize; // Size of this header 309 | DWORD dwMPQSize; //The size of the mpq archive 310 | WORD wUnused0C; // Seems to always be 0 311 | WORD wBlockSize; // Size of blocks in files equals 512 << wBlockSize 312 | DWORD dwHashTableOffset; // Offset to hash table 313 | DWORD dwBlockTableOffset; // Offset to block table 314 | DWORD dwHashTableSize; // Number of entries in hash table 315 | DWORD dwBlockTableSize; // Number of entries in block table 316 | }; 317 | 318 | //Archive handles may be typecasted to this struct so you can access 319 | //some of the archive's properties and the decrypted hash table and 320 | //block table directly. This struct is based on Storm's internal 321 | //struct for archive handles. 322 | struct MPQARCHIVE { 323 | // Arranged according to priority with lowest priority first 324 | MPQARCHIVE * lpNextArc; //0// Pointer to the next MPQARCHIVE struct. Pointer to addresses of first and last archives if last archive 325 | MPQARCHIVE * lpPrevArc; //4// Pointer to the previous MPQARCHIVE struct. 0xEAFC5E23 if first archive 326 | char szFileName[260]; //8// Filename of the archive 327 | HANDLE hFile; //10C// The archive's file handle 328 | DWORD dwFlags1; //110// Some flags, bit 0 seems to be set when opening an archive from a hard drive if bit 1 in the flags for SFileOpenArchive is set, bit 1 (0 based) seems to be set when opening an archive from a CD 329 | DWORD dwPriority; //114// Priority of the archive set when calling SFileOpenArchive 330 | MPQFILE * lpLastReadFile; //118// Pointer to the last read file's MPQFILE struct. This is cleared when finished reading a block 331 | DWORD dwUnk; //11C// Seems to always be 0 332 | DWORD dwBlockSize; //120// Size of file blocks in bytes 333 | BYTE * lpLastReadBlock; //124// Pointer to the read buffer for archive. This is cleared when finished reading a block 334 | DWORD dwBufferSize; //128// Size of the read buffer for archive. This is cleared when finished reading a block 335 | DWORD dwMPQStart; //12C// The starting offset of the archive 336 | DWORD dwMPQEnd; //130// The ending offset of the archive 337 | MPQHEADER * lpMPQHeader; //134// Pointer to the archive header 338 | BLOCKTABLEENTRY * lpBlockTable; //138// Pointer to the start of the block table 339 | HASHTABLEENTRY * lpHashTable; //13C// Pointer to the start of the hash table 340 | DWORD dwReadOffset; //140// Offset to the data for a file 341 | DWORD dwRefCount; //144// Count of references to this open archive. This is incremented for each file opened from the archive, and decremented for each file closed 342 | // Extra struct members used by SFmpq 343 | MPQHEADER MpqHeader; 344 | DWORD dwFlags; //The only flags that should be changed are MOAU_MAINTAIN_LISTFILE and MOAU_MAINTAIN_ATTRIBUTES, changing any others can have unpredictable effects 345 | LPSTR lpFileName; 346 | DWORD dwExtraFlags; 347 | }; 348 | 349 | //Handles to files in the archive may be typecasted to this struct 350 | //so you can access some of the file's properties directly. This 351 | //struct is based on Storm's internal struct for file handles. 352 | struct MPQFILE { 353 | MPQFILE * lpNextFile; //0// Pointer to the next MPQFILE struct. Pointer to addresses of first and last files if last file 354 | MPQFILE * lpPrevFile; //4// Pointer to the previous MPQFILE struct. 0xEAFC5E13 if first file 355 | char szFileName[260]; //8// Filename of the file 356 | HANDLE hFile; //10C// Always INVALID_HANDLE_VALUE for files in MPQ archives. For files not in MPQ archives, this is the file handle for the file and the rest of this struct is filled with zeros except for dwRefCount 357 | MPQARCHIVE * lpParentArc; //110// Pointer to the MPQARCHIVE struct of the archive in which the file is contained 358 | BLOCKTABLEENTRY * lpBlockEntry; //114// Pointer to the file's block table entry 359 | DWORD dwCryptKey; //118// Decryption key for the file 360 | DWORD dwFilePointer; //11C// Position of file pointer in the file 361 | DWORD dwUnk; //120// Seems to always be 0 362 | DWORD dwBlockCount; //124// Number of blocks in file 363 | DWORD * lpdwBlockOffsets; //128// Offsets to blocks in file. There are 1 more of these than the number of blocks. The values for this are set after the first read 364 | DWORD dwReadStarted; //12C// Set to 1 after first read 365 | BOOL bStreaming; //130// 1 when streaming a WAVE 366 | BYTE * lpLastReadBlock; //134// Pointer to the read buffer for file. This starts at the position specified in the last SFileSetFilePointer call. This is cleared when SFileSetFilePointer is called or when finished reading the block 367 | DWORD dwBytesRead; //138// Total bytes read from the current block in the open file. This is cleared when SFileSetFilePointer is called or when finished reading the block 368 | DWORD dwBufferSize; //13C// Size of the read buffer for file. This is cleared when SFileSetFilePointer is called or when finished reading the block 369 | DWORD dwRefCount; //140// Count of references to this open file 370 | // Extra struct members used by SFmpq 371 | HASHTABLEENTRY *lpHashEntry; 372 | LPSTR lpFileName; 373 | }; 374 | 375 | struct BLOCKTABLEENTRY { 376 | DWORD dwFileOffset; // Offset to file 377 | DWORD dwCompressedSize; // Compressed size of file 378 | DWORD dwFullSize; // Uncompressed size of file 379 | DWORD dwFlags; // Flags for file 380 | }; 381 | 382 | struct HASHTABLEENTRY { 383 | DWORD dwNameHashA; // First name hash of file 384 | DWORD dwNameHashB; // Second name hash of file 385 | LCID lcLocale; // Locale ID of file 386 | DWORD dwBlockTableIndex; // Index to the block table entry for the file 387 | }; 388 | 389 | // Defines for backward compatibility with old lmpqapi function names 390 | #define MpqAddFileToArcive MpqAddFileToArchive 391 | #define MpqOpenArchive SFileOpenArchive 392 | #define MpqOpenFileEx SFileOpenFileEx 393 | #define MpqGetFileSize SFileGetFileSize 394 | #define MpqReadFile SFileReadFile 395 | #define MpqCloseFile SFileCloseFile 396 | #define MpqCloseArchive SFileCloseArchive 397 | 398 | // Storm functions implemented by this library 399 | extern BOOL (WINAPI* SFileOpenArchive)(LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ); 400 | extern BOOL (WINAPI* SFileCloseArchive)(MPQHANDLE hMPQ); 401 | extern BOOL (WINAPI* SFileOpenFileAsArchive)(MPQHANDLE hSourceMPQ, LPCSTR lpFileName, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ); 402 | extern BOOL (WINAPI* SFileGetArchiveName)(MPQHANDLE hMPQ, LPCSTR lpBuffer, DWORD dwBufferLength); 403 | extern BOOL (WINAPI* SFileOpenFile)(LPCSTR lpFileName, MPQHANDLE *hFile); 404 | extern BOOL (WINAPI* SFileOpenFileEx)(MPQHANDLE hMPQ, LPCSTR lpFileName, DWORD dwSearchScope, MPQHANDLE *hFile); 405 | extern BOOL (WINAPI* SFileCloseFile)(MPQHANDLE hFile); 406 | extern DWORD (WINAPI* SFileGetFileSize)(MPQHANDLE hFile, LPDWORD lpFileSizeHigh); 407 | extern BOOL (WINAPI* SFileGetFileArchive)(MPQHANDLE hFile, MPQHANDLE *hMPQ); 408 | extern BOOL (WINAPI* SFileGetFileName)(MPQHANDLE hFile, LPCSTR lpBuffer, DWORD dwBufferLength); 409 | extern DWORD (WINAPI* SFileSetFilePointer)(MPQHANDLE hFile, long lDistanceToMove, PLONG lplDistanceToMoveHigh, DWORD dwMoveMethod); 410 | extern BOOL (WINAPI* SFileReadFile)(MPQHANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped); 411 | extern LCID (WINAPI* SFileSetLocale)(LCID nNewLocale); 412 | extern BOOL (WINAPI* SFileGetBasePath)(LPCSTR lpBuffer, DWORD dwBufferLength); 413 | extern BOOL (WINAPI* SFileSetBasePath)(LPCSTR lpNewBasePath); 414 | 415 | // Extra storm-related functions 416 | extern DWORD (WINAPI* SFileGetFileInfo)(MPQHANDLE hFile, DWORD dwInfoType); 417 | extern BOOL (WINAPI* SFileSetArchivePriority)(MPQHANDLE hMPQ, DWORD dwPriority); 418 | extern DWORD (WINAPI* SFileFindMpqHeader)(HANDLE hFile); 419 | extern BOOL (WINAPI* SFileListFiles)(MPQHANDLE hMPQ, LPCSTR lpFileLists, FILELISTENTRY *lpListBuffer, DWORD dwFlags); 420 | 421 | // Archive editing functions implemented by this library 422 | extern MPQHANDLE (WINAPI* MpqOpenArchiveForUpdate)(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive); 423 | extern DWORD (WINAPI* MpqCloseUpdatedArchive)(MPQHANDLE hMPQ, DWORD dwUnknown2); 424 | extern BOOL (WINAPI* MpqAddFileToArchive)(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags); 425 | extern BOOL (WINAPI* MpqAddWaveToArchive)(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwQuality); 426 | extern BOOL (WINAPI* MpqRenameFile)(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName); 427 | extern BOOL (WINAPI* MpqDeleteFile)(MPQHANDLE hMPQ, LPCSTR lpFileName); 428 | extern BOOL (WINAPI* MpqCompactArchive)(MPQHANDLE hMPQ); 429 | 430 | // Extra archive editing functions 431 | extern MPQHANDLE (WINAPI* MpqOpenArchiveForUpdateEx)(LPCSTR lpFileName, DWORD dwFlags, DWORD dwMaximumFilesInArchive, DWORD dwBlockSize); 432 | extern BOOL (WINAPI* MpqAddFileToArchiveEx)(MPQHANDLE hMPQ, LPCSTR lpSourceFileName, LPCSTR lpDestFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel); 433 | extern BOOL (WINAPI* MpqAddFileFromBufferEx)(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel); 434 | extern BOOL (WINAPI* MpqAddFileFromBuffer)(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags); 435 | extern BOOL (WINAPI* MpqAddWaveFromBuffer)(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwQuality); 436 | extern BOOL (WINAPI* MpqRenameAndSetFileLocale)(MPQHANDLE hMPQ, LPCSTR lpcOldFileName, LPCSTR lpcNewFileName, LCID nOldLocale, LCID nNewLocale); 437 | extern BOOL (WINAPI* MpqDeleteFileWithLocale)(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nLocale); 438 | extern BOOL (WINAPI* MpqSetFileLocale)(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID nOldLocale, LCID nNewLocale); 439 | 440 | // These functions do nothing. They are only provided for 441 | // compatibility with MPQ extractors that use storm. 442 | extern BOOL (WINAPI* SFileDestroy)(); 443 | extern void (WINAPI* StormDestroy)(); 444 | 445 | #ifdef __cplusplus 446 | }; // extern "C" 447 | #endif 448 | 449 | #endif 450 | 451 | -------------------------------------------------------------------------------- /SFmpqlib.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="SFmpqlib" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Static Library" 0x0104 6 | 7 | CFG=SFmpqlib - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "SFmpqlib.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "SFmpqlib.mak" CFG="SFmpqlib - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "SFmpqlib - Win32 Release" (based on "Win32 (x86) Static Library") 21 | !MESSAGE "SFmpqlib - Win32 Debug" (based on "Win32 (x86) Static Library") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "SFmpqlib___Win32_Release" 36 | # PROP BASE Intermediate_Dir "SFmpqlib___Win32_Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release" 42 | # PROP Target_Dir "" 43 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 44 | # ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_LIB" /D "SFMPQ_STATIC" /D "ZLIB_DLL" /D "BZ_NO_STDIO" /FD /c 45 | # SUBTRACT CPP /YX 46 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 47 | # ADD RSC /l 0x409 /d "NDEBUG" 48 | BSC32=bscmake.exe 49 | # ADD BASE BSC32 /nologo 50 | # ADD BSC32 /nologo 51 | LIB32=link.exe -lib 52 | # ADD BASE LIB32 /nologo 53 | # ADD LIB32 /nologo /out:"Release\SFmpq_static.lib" 54 | 55 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 56 | 57 | # PROP BASE Use_MFC 0 58 | # PROP BASE Use_Debug_Libraries 1 59 | # PROP BASE Output_Dir "SFmpqlib___Win32_Debug" 60 | # PROP BASE Intermediate_Dir "SFmpqlib___Win32_Debug" 61 | # PROP BASE Target_Dir "" 62 | # PROP Use_MFC 0 63 | # PROP Use_Debug_Libraries 1 64 | # PROP Output_Dir "Debug" 65 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug" 66 | # PROP Target_Dir "" 67 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c 68 | # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_LIB" /D "SFMPQ_STATIC" /D "ZLIB_DLL" /D "BZ_NO_STDIO" /FD /GZ /c 69 | # SUBTRACT CPP /YX 70 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 71 | # ADD RSC /l 0x409 /d "_DEBUG" 72 | BSC32=bscmake.exe 73 | # ADD BASE BSC32 /nologo 74 | # ADD BSC32 /nologo 75 | LIB32=link.exe -lib 76 | # ADD BASE LIB32 /nologo 77 | # ADD LIB32 /nologo /out:"Debug\SFmpq_static.lib" 78 | 79 | !ENDIF 80 | 81 | # Begin Target 82 | 83 | # Name "SFmpqlib - Win32 Release" 84 | # Name "SFmpqlib - Win32 Debug" 85 | # Begin Group "Source Files" 86 | 87 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 88 | # Begin Source File 89 | 90 | SOURCE=.\MpqBlockTable.cpp 91 | # End Source File 92 | # Begin Source File 93 | 94 | SOURCE=.\MpqCrypt.cpp 95 | # End Source File 96 | # Begin Source File 97 | 98 | SOURCE=.\MpqHashTable.cpp 99 | # End Source File 100 | # Begin Source File 101 | 102 | SOURCE=.\SFmpq_static.cpp 103 | # End Source File 104 | # Begin Source File 105 | 106 | SOURCE=.\SFmpqapi.cpp 107 | # End Source File 108 | # Begin Source File 109 | 110 | SOURCE=.\SFUtil.cpp 111 | # End Source File 112 | # End Group 113 | # Begin Group "Header Files" 114 | 115 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 116 | # Begin Source File 117 | 118 | SOURCE=.\MpqBlockTable.h 119 | # End Source File 120 | # Begin Source File 121 | 122 | SOURCE=.\MpqCrypt.h 123 | # End Source File 124 | # Begin Source File 125 | 126 | SOURCE=.\MpqHashTable.h 127 | # End Source File 128 | # Begin Source File 129 | 130 | SOURCE=.\SFmpq_static.h 131 | # End Source File 132 | # Begin Source File 133 | 134 | SOURCE=.\SFmpqapi.h 135 | # End Source File 136 | # Begin Source File 137 | 138 | SOURCE=.\SFTypes.h 139 | # End Source File 140 | # Begin Source File 141 | 142 | SOURCE=.\SFUtil.h 143 | # End Source File 144 | # End Group 145 | # Begin Group "SComp" 146 | 147 | # PROP Default_Filter "" 148 | # Begin Group "Base" 149 | 150 | # PROP Default_Filter "" 151 | # Begin Group "Source Files (Base)" 152 | 153 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 154 | # Begin Source File 155 | 156 | SOURCE=..\SComp\explode.c 157 | 158 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 159 | 160 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp" 161 | 162 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 163 | 164 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp" 165 | 166 | !ENDIF 167 | 168 | # End Source File 169 | # Begin Source File 170 | 171 | SOURCE=..\SComp\huffman.cpp 172 | 173 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 174 | 175 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp" 176 | 177 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 178 | 179 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp" 180 | 181 | !ENDIF 182 | 183 | # End Source File 184 | # Begin Source File 185 | 186 | SOURCE=..\SComp\implode.c 187 | 188 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 189 | 190 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp" 191 | 192 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 193 | 194 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp" 195 | 196 | !ENDIF 197 | 198 | # End Source File 199 | # Begin Source File 200 | 201 | SOURCE=..\SComp\SComp.cpp 202 | 203 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 204 | 205 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp" 206 | 207 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 208 | 209 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp" 210 | 211 | !ENDIF 212 | 213 | # End Source File 214 | # Begin Source File 215 | 216 | SOURCE=..\SComp\SErr.cpp 217 | 218 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 219 | 220 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp" 221 | 222 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 223 | 224 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp" 225 | 226 | !ENDIF 227 | 228 | # End Source File 229 | # Begin Source File 230 | 231 | SOURCE=..\SComp\SMem.cpp 232 | 233 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 234 | 235 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp" 236 | 237 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 238 | 239 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp" 240 | 241 | !ENDIF 242 | 243 | # End Source File 244 | # Begin Source File 245 | 246 | SOURCE=..\SComp\wave.cpp 247 | 248 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 249 | 250 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp" 251 | 252 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 253 | 254 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp" 255 | 256 | !ENDIF 257 | 258 | # End Source File 259 | # End Group 260 | # Begin Group "Header Files (Base)" 261 | 262 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 263 | # Begin Source File 264 | 265 | SOURCE=..\SComp\Huffman.h 266 | # End Source File 267 | # Begin Source File 268 | 269 | SOURCE=..\SComp\pklib.h 270 | # End Source File 271 | # Begin Source File 272 | 273 | SOURCE=..\SComp\SComp.h 274 | # End Source File 275 | # Begin Source File 276 | 277 | SOURCE=..\SComp\SErr.h 278 | # End Source File 279 | # Begin Source File 280 | 281 | SOURCE=..\SComp\SMem.h 282 | # End Source File 283 | # Begin Source File 284 | 285 | SOURCE=..\SComp\wave.h 286 | # End Source File 287 | # End Group 288 | # End Group 289 | # Begin Group "bzip2" 290 | 291 | # PROP Default_Filter "" 292 | # Begin Group "Source Files (bzip2)" 293 | 294 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 295 | # Begin Source File 296 | 297 | SOURCE=..\SComp\bzip2\blocksort.c 298 | 299 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 300 | 301 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/bzip2" 302 | 303 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 304 | 305 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/bzip2" 306 | 307 | !ENDIF 308 | 309 | # End Source File 310 | # Begin Source File 311 | 312 | SOURCE=..\SComp\bzip2\bzlib.c 313 | 314 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 315 | 316 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/bzip2" 317 | 318 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 319 | 320 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/bzip2" 321 | 322 | !ENDIF 323 | 324 | # End Source File 325 | # Begin Source File 326 | 327 | SOURCE=..\SComp\bzip2\compress.c 328 | 329 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 330 | 331 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/bzip2" 332 | 333 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 334 | 335 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/bzip2" 336 | 337 | !ENDIF 338 | 339 | # End Source File 340 | # Begin Source File 341 | 342 | SOURCE=..\SComp\bzip2\crctable.c 343 | 344 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 345 | 346 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/bzip2" 347 | 348 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 349 | 350 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/bzip2" 351 | 352 | !ENDIF 353 | 354 | # End Source File 355 | # Begin Source File 356 | 357 | SOURCE=..\SComp\bzip2\decompress.c 358 | 359 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 360 | 361 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/bzip2" 362 | 363 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 364 | 365 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/bzip2" 366 | 367 | !ENDIF 368 | 369 | # End Source File 370 | # Begin Source File 371 | 372 | SOURCE=..\SComp\bzip2\huffman.c 373 | 374 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 375 | 376 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/bzip2" 377 | 378 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 379 | 380 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/bzip2" 381 | 382 | !ENDIF 383 | 384 | # End Source File 385 | # Begin Source File 386 | 387 | SOURCE=..\SComp\bzip2\randtable.c 388 | 389 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 390 | 391 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/bzip2" 392 | 393 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 394 | 395 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/bzip2" 396 | 397 | !ENDIF 398 | 399 | # End Source File 400 | # End Group 401 | # Begin Group "Header Files (bzip2)" 402 | 403 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 404 | # Begin Source File 405 | 406 | SOURCE=..\SComp\bzip2\bzlib.h 407 | # End Source File 408 | # Begin Source File 409 | 410 | SOURCE=..\SComp\bzip2\bzlib_private.h 411 | # End Source File 412 | # End Group 413 | # End Group 414 | # Begin Group "zlib" 415 | 416 | # PROP Default_Filter "" 417 | # Begin Group "Source Files (zlib)" 418 | 419 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 420 | # Begin Source File 421 | 422 | SOURCE=..\SComp\zlib\adler32.c 423 | 424 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 425 | 426 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 427 | 428 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 429 | 430 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 431 | 432 | !ENDIF 433 | 434 | # End Source File 435 | # Begin Source File 436 | 437 | SOURCE=..\SComp\zlib\compress.c 438 | 439 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 440 | 441 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 442 | 443 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 444 | 445 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 446 | 447 | !ENDIF 448 | 449 | # End Source File 450 | # Begin Source File 451 | 452 | SOURCE=..\SComp\zlib\crc32.c 453 | 454 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 455 | 456 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 457 | 458 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 459 | 460 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 461 | 462 | !ENDIF 463 | 464 | # End Source File 465 | # Begin Source File 466 | 467 | SOURCE=..\SComp\zlib\deflate.c 468 | 469 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 470 | 471 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 472 | 473 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 474 | 475 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 476 | 477 | !ENDIF 478 | 479 | # End Source File 480 | # Begin Source File 481 | 482 | SOURCE=..\SComp\zlib\inffast.c 483 | 484 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 485 | 486 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 487 | 488 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 489 | 490 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 491 | 492 | !ENDIF 493 | 494 | # End Source File 495 | # Begin Source File 496 | 497 | SOURCE=..\SComp\zlib\inflate.c 498 | 499 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 500 | 501 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 502 | 503 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 504 | 505 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 506 | 507 | !ENDIF 508 | 509 | # End Source File 510 | # Begin Source File 511 | 512 | SOURCE=..\SComp\zlib\inftrees.c 513 | 514 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 515 | 516 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 517 | 518 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 519 | 520 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 521 | 522 | !ENDIF 523 | 524 | # End Source File 525 | # Begin Source File 526 | 527 | SOURCE=..\SComp\zlib\trees.c 528 | 529 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 530 | 531 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 532 | 533 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 534 | 535 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 536 | 537 | !ENDIF 538 | 539 | # End Source File 540 | # Begin Source File 541 | 542 | SOURCE=..\SComp\zlib\uncompr.c 543 | 544 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 545 | 546 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 547 | 548 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 549 | 550 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 551 | 552 | !ENDIF 553 | 554 | # End Source File 555 | # Begin Source File 556 | 557 | SOURCE=..\SComp\zlib\zutil.c 558 | 559 | !IF "$(CFG)" == "SFmpqlib - Win32 Release" 560 | 561 | # PROP Intermediate_Dir "SFmpqlib___Win32_Release/SComp/zlib" 562 | 563 | !ELSEIF "$(CFG)" == "SFmpqlib - Win32 Debug" 564 | 565 | # PROP Intermediate_Dir "SFmpqlib___Win32_Debug/SComp/zlib" 566 | 567 | !ENDIF 568 | 569 | # End Source File 570 | # End Group 571 | # Begin Group "Header Files (zlib)" 572 | 573 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 574 | # Begin Source File 575 | 576 | SOURCE=..\SComp\zlib\zconf.h 577 | # End Source File 578 | # Begin Source File 579 | 580 | SOURCE=..\SComp\zlib\zlib.h 581 | # End Source File 582 | # End Group 583 | # End Group 584 | # End Group 585 | # End Target 586 | # End Project 587 | -------------------------------------------------------------------------------- /SFmpqlib.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 28 | 31 | 34 | 37 | 40 | 43 | 58 | 61 | 66 | 69 | 74 | 77 | 80 | 85 | 88 | 91 | 92 | 102 | 105 | 108 | 111 | 114 | 117 | 132 | 135 | 140 | 143 | 148 | 151 | 154 | 159 | 162 | 165 | 166 | 167 | 168 | 169 | 170 | 174 | 177 | 178 | 181 | 182 | 185 | 186 | 189 | 192 | 196 | 197 | 200 | 204 | 205 | 206 | 209 | 212 | 216 | 217 | 220 | 224 | 225 | 226 | 229 | 230 | 231 | 235 | 238 | 239 | 242 | 243 | 246 | 247 | 250 | 251 | 254 | 255 | 258 | 259 | 262 | 263 | 264 | 267 | 270 | 274 | 277 | 278 | 281 | 282 | 285 | 286 | 289 | 290 | 293 | 294 | 297 | 298 | 299 | 303 | 306 | 309 | 314 | 315 | 318 | 323 | 324 | 325 | 328 | 331 | 336 | 337 | 340 | 345 | 346 | 347 | 350 | 353 | 358 | 359 | 362 | 367 | 368 | 369 | 372 | 375 | 380 | 381 | 384 | 389 | 390 | 391 | 394 | 397 | 402 | 403 | 406 | 411 | 412 | 413 | 416 | 419 | 424 | 425 | 428 | 433 | 434 | 435 | 438 | 441 | 446 | 447 | 450 | 455 | 456 | 457 | 458 | 459 | 462 | 466 | 469 | 470 | 473 | 474 | 475 | 479 | 482 | 485 | 489 | 490 | 493 | 497 | 498 | 499 | 502 | 505 | 509 | 510 | 513 | 517 | 518 | 519 | 522 | 525 | 529 | 530 | 533 | 537 | 538 | 539 | 542 | 545 | 549 | 550 | 553 | 557 | 558 | 559 | 562 | 565 | 569 | 570 | 573 | 577 | 578 | 579 | 582 | 585 | 589 | 590 | 593 | 597 | 598 | 599 | 602 | 605 | 609 | 610 | 613 | 617 | 618 | 619 | 620 | 621 | 624 | 628 | 631 | 632 | 635 | 636 | 637 | 641 | 644 | 647 | 651 | 652 | 655 | 659 | 660 | 661 | 664 | 667 | 671 | 672 | 675 | 679 | 680 | 681 | 684 | 687 | 691 | 692 | 695 | 699 | 700 | 701 | 704 | 707 | 711 | 712 | 715 | 719 | 720 | 721 | 724 | 727 | 731 | 732 | 735 | 739 | 740 | 741 | 744 | 747 | 751 | 752 | 755 | 759 | 760 | 761 | 764 | 767 | 771 | 772 | 775 | 779 | 780 | 781 | 784 | 787 | 791 | 792 | 795 | 799 | 800 | 801 | 804 | 807 | 811 | 812 | 815 | 819 | 820 | 821 | 824 | 827 | 831 | 832 | 835 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | -------------------------------------------------------------------------------- /WinError.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "WinError" 2 | Option Explicit 3 | 4 | ' GetLastError and the constants for the values returned by it 5 | ' (only the ones known to be used by Storm or Lmpqapi are included) 6 | 7 | Declare Function GetLastError Lib "Kernel32" () As Long 8 | 9 | Public Const ERROR_SUCCESS As Long = 0 10 | Public Const NO_ERROR As Long = 0 11 | Public Const ERROR_FILE_NOT_FOUND As Long = 2 12 | Public Const ERROR_OUTOFMEMORY As Long = 14 13 | Public Const ERROR_INVALID_PARAMETER As Long = 87 14 | Public Const ERROR_DISK_FULL As Long = 112 15 | Public Const ERROR_ALREADY_EXISTS As Long = 183 16 | Public Const ERROR_FILE_INVALID As Long = 1006 17 | Public Const ERROR_UNKNOWN_PROPERTY As Long = 1608 18 | 19 | -------------------------------------------------------------------------------- /about: -------------------------------------------------------------------------------- 1 | 2 | About ShadowFlare MPQ API Library 3 |
  ShadowFlare MPQ API Library v1.08 (c) ShadowFlare Software 2002-2010
  4 | 
  5 |   This library emulates the interface of Lmpqapi and Storm MPQ
  6 |   functions, so it may be used as a replacement for them in
  7 |   MPQ extractors/archivers without even needing to recompile
  8 |   the program that uses Lmpqapi or Storm.  It has a few features
  9 |   not included in Lmpqapi and Storm, such as extra flags for some
 10 |   functions, setting the locale ID of existing files, and adding
 11 |   files without having to write them somewhere else first.  Also,
 12 |   MPQ handles used by functions prefixed with "SFile" and "Mpq"
 13 |   can be used interchangably; all functions use the same type
 14 |   of MPQ handles.  You cannot, however, use handles from this
 15 |   library with storm or lmpqapi or vice-versa.  Doing so will
 16 |   most likely result in a crash.
 17 | 
 18 |   This library does not require Storm to be able to decompress
 19 |   or compress files.
 20 | 
 21 |   Revision History:
 22 |   (Release date) 1.08 (ShadowFlare)
 23 |   - Fixed a buffer overflow that would occur when reading files
 24 |     if neither using a buffer that is large enough to contain the
 25 |     entire file nor has a size that is a multiple of 4096
 26 |   - Added SFileOpenFileAsArchive which opens an archive that is
 27 |     contained within an already open archive
 28 |   - Added MpqRenameAndSetFileLocale and MpqDeleteFileWithLocale.
 29 |     These have extra parameters that allow you to use them with
 30 |     files having language codes other than what was last set
 31 |     using SFileSetLocale
 32 |   - Fixed a bug that caused (listfile) to get cleared if adding
 33 |     files with a locale ID other than 0
 34 |   - Added MpqOpenArchiveForUpdateEx which allows creating
 35 |     archives with different block sizes
 36 |   - SFileListFiles can list the contents of bncache.dat without
 37 |     needing an external list
 38 | 
 39 |   06/12/2002 1.07 (ShadowFlare)
 40 |   - No longer requires Storm.dll to compress or decompress
 41 |     Warcraft III files
 42 |   - Added SFileListFiles for getting names and information
 43 |     about all of the files in an archive
 44 |   - Fixed a bug with renaming and deleting files
 45 |   - Fixed a bug with adding wave compressed files with
 46 |     low compression setting
 47 |   - Added a check in MpqOpenArchiveForUpdate for proper
 48 |     dwMaximumFilesInArchive values (should be a number that
 49 |     is a power of 2).  If it is not a proper value, it will
 50 |     be rounded up to the next higher power of 2
 51 | 
 52 |   05/09/2002 1.06 (ShadowFlare)
 53 |   - Compresses files without Storm.dll!
 54 |   - If Warcraft III is installed, this library will be able to
 55 |     find Storm.dll on its own. (Storm.dll is needed to
 56 |     decompress Warcraft III files)
 57 |   - Fixed a bug where an embedded archive and the file that
 58 |     contains it would be corrupted if the archive was modified
 59 |   - Able to open all .w3m maps now
 60 | 
 61 |   29/06/2002 1.05 (ShadowFlare)
 62 |   - Supports decompressing files from Warcraft III MPQ archives
 63 |     if using Storm.dll from Warcraft III
 64 |   - Added MpqAddFileToArchiveEx and MpqAddFileFromBufferEx for
 65 |     using extra compression types
 66 | 
 67 |   29/05/2002 1.04 (ShadowFlare)
 68 |   - Files can be compressed now!
 69 |   - Fixed a bug in SFileReadFile when reading data not aligned
 70 |     to the block size
 71 |   - Optimized some of SFileReadFile's code.  It can read files
 72 |     faster now
 73 |   - SFile functions may now be used to access files not in mpq
 74 |     archives as you can with the real storm functions
 75 |   - MpqCompactArchive will no longer corrupt files with the
 76 |     MODCRYPTKEY flag as long as the file is either compressed,
 77 |     listed in "(listfile)", is "(listfile)", or is located in
 78 |     the same place in the compacted archive; so it is safe
 79 |     enough to use it on almost any archive
 80 |   - Added MpqAddWaveFromBuffer
 81 |   - Better handling of archives with no files
 82 |   - Fixed compression with COMPRESS2 flag
 83 | 
 84 |   15/05/2002 1.03 (ShadowFlare)
 85 |   - Supports adding files with the compression attribute (does
 86 |     not actually compress files).  Now archives created with
 87 |     this dll can have files added to them through lmpqapi
 88 |     without causing staredit to crash
 89 |   - SFileGetBasePath and SFileSetBasePath work more like their
 90 |     Storm equivalents now
 91 |   - Implemented MpqCompactArchive, but it is not finished yet.
 92 |     In its current state, I would recommend against using it
 93 |     on archives that contain files with the MODCRYPTKEY flag,
 94 |     since it will corrupt any files with that flag
 95 |   - Added SFMpqGetVersionString2 which may be used in Visual
 96 |     Basic to get the version string
 97 | 
 98 |   07/05/2002 1.02 (ShadowFlare)
 99 |   - SFileReadFile no longer passes the lpOverlapped parameter it
100 |     receives to ReadFile.  This is what was causing the function
101 |     to fail when used in Visual Basic
102 |   - Added support for more Storm MPQ functions
103 |   - GetLastError may now be used to get information about why a
104 |     function failed
105 | 
106 |   01/05/2002 1.01 (ShadowFlare)
107 |   - Added ordinals for Storm MPQ functions
108 |   - Fixed MPQ searching functionality of SFileOpenFileEx
109 |   - Added a check for whether a valid handle is given when
110 |     SFileCloseArchive is called
111 |   - Fixed functionality of SFileSetArchivePriority when multiple
112 |     files are open
113 |   - File renaming works for all filenames now
114 |   - SFileReadFile no longer reallocates the buffer for each block
115 |     that is decompressed.  This should make SFileReadFile at least
116 |     a little faster
117 | 
118 |   30/04/2002 1.00 (ShadowFlare)
119 |   - First version.
120 |   - Compression not yet supported
121 |   - Does not use SetLastError yet, so GetLastError will not return any
122 |     errors that have to do with this library
123 |   - MpqCompactArchive not implemented
124 | 
125 |   Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare)
126 |   Download the newest version from ShadowFlare's Realm at http://sfsrealm.hopto.org/
127 | 
128 |   License information:
129 | 
130 |   Copyright (c) 2002-2010, ShadowFlare <blakflare@hotmail.com>
131 |   All rights reserved.
132 | 
133 |   Redistribution and use in source and binary forms, with or without
134 |   modification, are permitted provided that the following conditions
135 |   are met:
136 | 
137 |   1. Redistributions of source code must retain the above copyright
138 |      notice, this list of conditions and the following disclaimer.
139 |   2. Redistributions in binary form must reproduce the above copyright
140 |      notice, this list of conditions and the following disclaimer in the
141 |      documentation and/or other materials provided with the distribution.
142 | 
143 |   THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
144 |   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
145 |   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
146 |   ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
147 |   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
148 |   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
149 |   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
150 |   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
151 |   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
152 |   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
153 |   SUCH DAMAGE.
154 | 155 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2010, ShadowFlare 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | SUCH DAMAGE. -------------------------------------------------------------------------------- /linux/SFmpqapi.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 84 | 85 | -------------------------------------------------------------------------------- /linux/SFmpqapi.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /linux/poppack.h: -------------------------------------------------------------------------------- 1 | #pragma pack(pop) 2 | -------------------------------------------------------------------------------- /linux/pshpack1.h: -------------------------------------------------------------------------------- 1 | #pragma pack(push,1) 2 | -------------------------------------------------------------------------------- /linux/windows.cpp: -------------------------------------------------------------------------------- 1 | /* License information for this code is in license.txt */ 2 | 3 | #include "windows.h" 4 | 5 | DWORD dwAppLastError=0; 6 | 7 | void WINAPI SetLastError(DWORD dwLastError) 8 | { 9 | dwAppLastError=dwLastError; 10 | } 11 | 12 | DWORD WINAPI GetLastError() 13 | { 14 | return dwAppLastError; 15 | } 16 | 17 | DWORD WINAPI GetCurrentDirectory(DWORD dwBufferLength, LPSTR lpBuffer) 18 | { 19 | if (lpBuffer==0) return 0; 20 | strncpy(lpBuffer,"./",dwBufferLength); 21 | return strlen(lpBuffer)+1; 22 | } 23 | 24 | DWORD WINAPI GetDriveType(LPCSTR lpRootPath) 25 | { 26 | return DRIVE_FIXED; 27 | } 28 | 29 | HANDLE WINAPI CreateFile(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) 30 | { 31 | if (lpFileName==0) return INVALID_HANDLE_VALUE; 32 | int nFlags,hFile; 33 | if ((dwDesiredAccess&GENERIC_READ && dwDesiredAccess&GENERIC_WRITE) || dwDesiredAccess&GENERIC_ALL) { 34 | nFlags = O_RDWR; 35 | } 36 | else if (dwDesiredAccess&GENERIC_READ) { 37 | nFlags = O_RDONLY; 38 | } 39 | else if (dwDesiredAccess&GENERIC_WRITE) { 40 | nFlags = O_WRONLY; 41 | } 42 | else { 43 | nFlags = 0; 44 | 45 | } 46 | switch (dwCreationDisposition) { 47 | case CREATE_NEW: 48 | hFile = open(lpFileName,0); 49 | if (hFile!=-1) {close(hFile);return INVALID_HANDLE_VALUE;} 50 | nFlags |= O_CREAT; 51 | break; 52 | case CREATE_ALWAYS: 53 | nFlags |= O_CREAT|O_TRUNC; 54 | break; 55 | case OPEN_EXISTING: 56 | break; 57 | case OPEN_ALWAYS: 58 | hFile = open(lpFileName,0); 59 | if (hFile==-1) nFlags |= O_CREAT; 60 | else close(hFile); 61 | break; 62 | case TRUNCATE_EXISTING: 63 | nFlags |= O_TRUNC; 64 | break; 65 | default: 66 | return INVALID_HANDLE_VALUE; 67 | } 68 | hFile = open(lpFileName,nFlags); 69 | if (hFile!=-1) chmod(lpFileName,0644); 70 | return (HANDLE)hFile; 71 | } 72 | 73 | BOOL WINAPI CloseHandle(HANDLE hObject) 74 | { 75 | if (hObject==INVALID_HANDLE_VALUE) return 0; 76 | return (BOOL)(close((int)hObject) == 0); 77 | } 78 | 79 | DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) 80 | { 81 | if (hFile==INVALID_HANDLE_VALUE) return (DWORD)-1; 82 | 83 | struct stat fileinfo; 84 | fstat((int)hFile, &fileinfo); 85 | 86 | if (lpFileSizeHigh) *lpFileSizeHigh = 0; 87 | return (DWORD)fileinfo.st_size; 88 | } 89 | 90 | DWORD WINAPI SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) 91 | { 92 | if (hFile==INVALID_HANDLE_VALUE) return (DWORD)-1; 93 | 94 | switch (dwMoveMethod) { 95 | case FILE_BEGIN: 96 | return (DWORD)lseek((int)hFile, lDistanceToMove, SEEK_SET); 97 | case FILE_CURRENT: 98 | return (DWORD)lseek((int)hFile, lDistanceToMove, SEEK_CUR); 99 | case FILE_END: 100 | return (DWORD)lseek((int)hFile, lDistanceToMove, SEEK_END); 101 | } 102 | return (DWORD)-1; 103 | } 104 | 105 | BOOL WINAPI SetEndOfFile(HANDLE hFile) 106 | { 107 | if (hFile==INVALID_HANDLE_VALUE) return 0; 108 | 109 | return (BOOL)(ftruncate((int)hFile, lseek((int)hFile, 0, SEEK_CUR)) == 0); 110 | } 111 | 112 | BOOL WINAPI ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped) 113 | { 114 | if (hFile==INVALID_HANDLE_VALUE || lpBuffer==0) return 0; 115 | 116 | ssize_t count; 117 | if ((count = read((int)hFile, lpBuffer, nNumberOfBytesToRead)) == -1) { 118 | if (lpNumberOfBytesRead) *lpNumberOfBytesRead = 0; 119 | return FALSE; 120 | } 121 | if (lpNumberOfBytesRead) *lpNumberOfBytesRead = count; 122 | return TRUE; 123 | } 124 | 125 | BOOL WINAPI WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped) 126 | { 127 | if (hFile==INVALID_HANDLE_VALUE || lpBuffer==0) return 0; 128 | 129 | ssize_t count; 130 | if ((count = write((int)hFile, lpBuffer, nNumberOfBytesToWrite)) == -1) { 131 | if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = 0; 132 | return FALSE; 133 | } 134 | if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = count; 135 | return TRUE; 136 | } 137 | 138 | BOOL WINAPI DeleteFile(LPCSTR lpFileName) 139 | { 140 | if (lpFileName==0) return FALSE; 141 | return (BOOL)(unlink(lpFileName) == 0); 142 | } 143 | 144 | char * strlwr(char *lpString) 145 | { 146 | if (lpString==0) return 0; 147 | for (char *lpChar=lpString;lpChar[0]==0;lpChar++) 148 | lpChar[0] = tolower(lpChar[0]); 149 | return lpString; 150 | } 151 | 152 | char * strupr(char *lpString) 153 | { 154 | if (lpString==0) return 0; 155 | for (char *lpChar=lpString;lpChar[0]==0;lpChar++) 156 | lpChar[0] = toupper(lpChar[0]); 157 | return lpString; 158 | } 159 | 160 | /*char * strdup(const char *lpString) 161 | { 162 | if (lpString==0) return 0; 163 | char *lpStrCopy = (char *)malloc(strlen(lpString)+1); 164 | if (lpStrCopy==0) return 0; 165 | strcpy(lpStrCopy,lpString); 166 | return lpStrCopy; 167 | }*/ 168 | 169 | int memicmp(const char *lpString1, const char *lpString2, size_t dwSize) 170 | { 171 | if (lpString1==0) return -1; 172 | if (lpString2==0) return 1; 173 | if (dwSize==0) return 0; 174 | size_t i; 175 | char ch1,ch2; 176 | for (i=0;i ch2) return 1; 180 | else if (ch1 < ch2) return -1; 181 | } 182 | return 0; 183 | } 184 | 185 | void SlashToBackslash(char *lpPath) 186 | { 187 | if (lpPath==0) return; 188 | for (;lpPath[0]!=0;lpPath++) 189 | if (lpPath[0]=='/') lpPath[0]='\\'; 190 | } 191 | 192 | void BackslashToSlash(char *lpPath) 193 | { 194 | if (lpPath==0) return; 195 | for (;lpPath[0]!=0;lpPath++) 196 | if (lpPath[0]=='\\') lpPath[0]='/'; 197 | } 198 | 199 | -------------------------------------------------------------------------------- /linux/windows.h: -------------------------------------------------------------------------------- 1 | /* License information for this code is in license.txt */ 2 | 3 | #ifndef WINDOWS_H_INCLUDED 4 | #define WINDOWS_H_INCLUDED 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define LINUX_PORT 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | // Function related defines 21 | #define __cdecl 22 | #define __stdcall 23 | #define WINAPI __stdcall 24 | #define APIENTRY __stdcall 25 | #define __declspec(x) 26 | #define __inline inline 27 | #define __forceinline inline 28 | 29 | #define CONST const 30 | 31 | // Type defines 32 | typedef uint8_t BYTE; 33 | typedef uint16_t WORD; 34 | typedef uint32_t DWORD; 35 | typedef int16_t SHORT; 36 | typedef uint16_t USHORT; 37 | typedef DWORD LCID; 38 | typedef int32_t LONG; 39 | typedef LONG * PLONG; 40 | typedef int BOOL; 41 | typedef void * LPVOID; 42 | typedef CONST void *LPCVOID; 43 | typedef char CHAR; 44 | typedef char * LPSTR; 45 | typedef const char * LPCSTR; 46 | typedef DWORD * LPDWORD; 47 | typedef BYTE * LPBYTE; 48 | typedef LPVOID HANDLE; 49 | typedef HANDLE HINSTANCE; 50 | 51 | // Structs 52 | typedef struct _OVERLAPPED { 53 | DWORD Internal; 54 | DWORD InternalHigh; 55 | DWORD Offset; 56 | DWORD OffsetHigh; 57 | HANDLE hEvent; 58 | } OVERLAPPED, *LPOVERLAPPED; 59 | typedef struct _SECURITY_ATTRIBUTES { 60 | DWORD nLength; 61 | LPVOID lpSecurityDescriptor; 62 | BOOL bInheritHandle; 63 | } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; 64 | 65 | // Constants 66 | #define FALSE 0 67 | #define TRUE 1 68 | #define MAX_PATH 260 69 | #define INVALID_HANDLE_VALUE ((HANDLE)-1) 70 | #define INVALID_FILE_SIZE ((DWORD)-1) 71 | #define INVALID_SET_FILE_POINTER ((DWORD)-1) 72 | #define DLL_PROCESS_ATTACH 1 73 | #define DLL_THREAD_ATTACH 2 74 | #define DLL_THREAD_DETACH 3 75 | #define DLL_PROCESS_DETACH 0 76 | #define PAGE_NOACCESS 0x01 77 | #define PAGE_READONLY 0x02 78 | #define PAGE_READWRITE 0x04 79 | #define PAGE_WRITECOPY 0x08 80 | #define PAGE_EXECUTE 0x10 81 | #define PAGE_EXECUTE_READ 0x20 82 | #define PAGE_EXECUTE_READWRITE 0x40 83 | #define PAGE_EXECUTE_WRITECOPY 0x80 84 | #define PAGE_GUARD 0x100 85 | #define PAGE_NOCACHE 0x200 86 | #define PAGE_WRITECOMBINE 0x400 87 | #define MEM_COMMIT 0x1000 88 | #define MEM_RESERVE 0x2000 89 | #define MEM_DECOMMIT 0x4000 90 | #define MEM_RELEASE 0x8000 91 | #define MEM_FREE 0x10000 92 | #define MEM_PRIVATE 0x20000 93 | #define MEM_MAPPED 0x40000 94 | #define MEM_RESET 0x80000 95 | #define MEM_TOP_DOWN 0x100000 96 | #define MEM_4MB_PAGES 0x80000000 97 | #define DRIVE_UNKNOWN 0 98 | #define DRIVE_NO_ROOT_DIR 1 99 | #define DRIVE_REMOVABLE 2 100 | #define DRIVE_FIXED 3 101 | #define DRIVE_REMOTE 4 102 | #define DRIVE_CDROM 5 103 | #define DRIVE_RAMDISK 6 104 | #define GENERIC_READ (0x80000000L) 105 | #define GENERIC_WRITE (0x40000000L) 106 | #define GENERIC_EXECUTE (0x20000000L) 107 | #define GENERIC_ALL (0x10000000L) 108 | #define FILE_SHARE_READ 0x00000001 109 | #define FILE_SHARE_WRITE 0x00000002 110 | #define FILE_SHARE_DELETE 0x00000004 111 | #define CREATE_NEW 1 112 | #define CREATE_ALWAYS 2 113 | #define OPEN_EXISTING 3 114 | #define OPEN_ALWAYS 4 115 | #define TRUNCATE_EXISTING 5 116 | #define FILE_BEGIN 0 117 | #define FILE_CURRENT 1 118 | #define FILE_END 2 119 | #define NO_ERROR 0L 120 | #define ERROR_FILE_NOT_FOUND 2L 121 | #define ERROR_ACCESS_DENIED 5L 122 | #define ERROR_INVALID_PARAMETER 87L // dderror 123 | #define ERROR_ALREADY_EXISTS 183L 124 | #define ERROR_FILE_INVALID 1006L 125 | #define ERROR_UNKNOWN_PROPERTY 1608L 126 | 127 | // Declarations for Windows API functions 128 | void WINAPI SetLastError(DWORD dwLastError); 129 | DWORD WINAPI GetLastError(); 130 | DWORD WINAPI GetCurrentDirectory(DWORD dwBufferLength, LPSTR lpBuffer); 131 | DWORD WINAPI GetDriveType(LPCSTR lpRootPath); 132 | HANDLE WINAPI CreateFile(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); 133 | BOOL WINAPI CloseHandle(HANDLE hObject); 134 | DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh); 135 | DWORD WINAPI SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod); 136 | BOOL WINAPI SetEndOfFile(HANDLE hFile); 137 | BOOL WINAPI ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped); 138 | BOOL WINAPI WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped); 139 | BOOL WINAPI DeleteFile(LPCSTR lpFileName); 140 | 141 | // Declarations for C runtime functions 142 | char * strlwr(char *lpString); 143 | char * strupr(char *lpString); 144 | //char * strdup(const char *lpString); 145 | #define stricmp strcasecmp 146 | #define strnicmp strncasecmp 147 | int memicmp(const char *lpString1, const char *lpString2, size_t dwSize); 148 | 149 | // Other functions 150 | void SlashToBackslash(char *lpPath); 151 | void BackslashToSlash(char *lpPath); 152 | 153 | #ifdef __cplusplus 154 | }; // extern "C" 155 | #endif 156 | 157 | #endif 158 | 159 | -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- 1 | /* License information for this code is in license.txt */ 2 | 3 | //{{NO_DEPENDENCIES}} 4 | // Microsoft Developer Studio generated include file. 5 | // Used by SFmpqapi.rc 6 | // 7 | 8 | // Next default values for new objects 9 | // 10 | #ifdef APSTUDIO_INVOKED 11 | #ifndef APSTUDIO_READONLY_SYMBOLS 12 | #define _APS_NEXT_RESOURCE_VALUE 105 13 | #define _APS_NEXT_COMMAND_VALUE 40001 14 | #define _APS_NEXT_CONTROL_VALUE 1000 15 | #define _APS_NEXT_SYMED_VALUE 101 16 | #endif 17 | #endif 18 | --------------------------------------------------------------------------------