Current News
Archived News
Search News
Discussion Forum


Old Forum
Install Programs More Downloads...
Troubleshooting
Source Code
Format Specs.
Misc. Information
Non-SF Stuff
Links




CommitLineData
62046253 1Attribute VB_Name = "SFmpqapi"
2Option Explicit
3
4' ShadowFlare MPQ API Library. (c) ShadowFlare Software 2002
5
6' All functions below are actual functions that are part of this
7' library and do not need any additional dll files. It does not
8' even require Storm to be able to decompress or compress files.
9
10' This library emulates the interface of Lmpqapi and Storm MPQ
11' functions, so it may be used as a replacement for them in
12' MPQ extractors/archivers without even needing to recompile
13' the program that uses Lmpqapi or Storm. It has a few features
14' not included in Lmpqapi and Storm, such as extra flags for some
15' functions, setting the locale ID of existing files, and adding
16' files without having to write them somewhere else first. Also,
17' MPQ handles used by functions prefixed with "SFile" and "Mpq"
18' can be used interchangably; all functions use the same type
19' of MPQ handles. You cannot, however, use handles from this
20' library with storm or lmpqapi or vice-versa. Doing so will
21' most likely result in a crash.
22
23' Revision History:
5f007675 24' 06/12/2002 1.07 (ShadowFlare)
62046253 25' - No longer requires Storm.dll to compress or decompress
26' Warcraft III files
27' - Added SFileListFiles for getting names and information
28' about all of the files in an archive
29' - Fixed a bug with renaming and deleting files
5f007675 30' - Fixed a bug with adding wave compressed files with
31' low compression setting
32' - Added a check in MpqOpenArchiveForUpdate for proper
33' dwMaximumFilesInArchive values (should be a number that
34' is a power of 2). If it is not a proper value, it will
35' be rounded up to the next higher power of 2
62046253 36
37' 05/09/2002 1.06 (ShadowFlare)
38' - Compresses files without Storm.dll!
39' - If Warcraft III is installed, this library will be able to
40' find Storm.dll on its own. (Storm.dll is needed to
41' decompress Warcraft III files)
42' - Fixed a bug where an embedded archive and the file that
43' contains it would be corrupted if the archive was modified
44' - Able to open all .w3m maps now
45
46' 29/06/2002 1.05 (ShadowFlare)
47' - Supports decompressing files from Warcraft III MPQ archives
48' if using Storm.dll from Warcraft III
49' - Added MpqAddFileToArchiveEx and MpqAddFileFromBufferEx for
50' using extra compression types
51
52' 29/05/2002 1.04 (ShadowFlare)
53' - Files can be compressed now!
54' - Fixed a bug in SFileReadFile when reading data not aligned
55' to the block size
56' - Optimized some of SFileReadFile's code. It can read files
57' faster now
58' - SFile functions may now be used to access files not in mpq
59' archives as you can with the real storm functions
60' - MpqCompactArchive will no longer corrupt files with the
61' MODCRYPTKEY flag as long as the file is either compressed,
62' listed in "(listfile)", is "(listfile)", or is located in
63' the same place in the compacted archive; so it is safe
64' enough to use it on almost any archive
65' - Added MpqAddWaveFromBuffer
66' - Better handling of archives with no files
67' - Fixed compression with COMPRESS2 flag
68
69' 15/05/2002 1.03 (ShadowFlare)
70' - Supports adding files with the compression attribute (does
71' not actually compress files). Now archives created with
72' this dll can have files added to them through lmpqapi
73' without causing staredit to crash
74' - SFileGetBasePath and SFileSetBasePath work more like their
75' Storm equivalents now
76' - Implemented MpqCompactArchive, but it is not finished yet.
77' In its current state, I would recommend against using it
78' on archives that contain files with the MODCRYPTKEY flag,
79' since it will corrupt any files with that flag
80' - Added SFMpqGetVersionString2 which may be used in Visual
81' Basic to get the version string
82
83' 07/05/2002 1.02 (ShadowFlare)
84' - SFileReadFile no longer passes the lpOverlapped parameter it
85' receives to ReadFile. This is what was causing the function
86' to fail when used in Visual Basic
87' - Added support for more Storm MPQ functions
88' - GetLastError may now be used to get information about why a
89' function failed
90
91' 01/05/2002 1.01 (ShadowFlare)
92' - Added ordinals for Storm MPQ functions
93' - Fixed MPQ searching functionality of SFileOpenFileEx
94' - Added a check for whether a valid handle is given when
95' SFileCloseArchive is called
96' - Fixed functionality of SFileSetArchivePriority when multiple
97' files are open
98' - File renaming works for all filenames now
99' - SFileReadFile no longer reallocates the buffer for each block
100' that is decompressed. This should make SFileReadFile at least
101' a little faster
102
103' 30/04/2002 1.00 (ShadowFlare)
104' - First version.
105' - Compression not yet supported
106' - Does not use SetLastError yet, so GetLastError will not return any
107' errors that have to do with this library
108' - MpqCompactArchive not implemented
109
110' This library is freeware, you can do anything you want with it but with
111' one exception. If you use it in your program, you must specify this fact
112' in Help|About box or in similar way. You can obtain version string using
113' SFMpqGetVersionString call.
114
115' THIS LIBRARY IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED
116' OR IMPLIED. YOU USE AT YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR
117' DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING
118' OR MISUSING THIS SOFTWARE.
119
120' Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare)
121
122Type SFMPQVERSION
123 Major As Integer
124 Minor As Integer
125 Revision As Integer
126 Subrevision As Integer
127End Type
128
129' MpqInitialize does nothing. It is only provided for
130' compatibility with MPQ archivers that use lmpqapi.
131Declare Function MpqInitialize Lib "SFmpq.dll" () As Boolean
132
133Declare Function MpqGetVersionString Lib "SFmpq.dll" () As String
134Declare Function MpqGetVersion Lib "SFmpq.dll" () As Single
135
136Declare Sub SFMpqDestroy Lib "SFmpq.dll" () ' This no longer needs to be called. It is only provided for compatibility with older versions
137
138' SFMpqGetVersionString2's return value is the required length of the buffer plus
139' the terminating null, so use SFMpqGetVersionString2(ByVal 0&, 0) to get the length.
140Declare Function SFMpqGetVersionString Lib "SFmpq.dll" () As String
141Declare Function SFMpqGetVersionString2 Lib "SFmpq.dll" (ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Long
142Declare Function SFMpqGetVersion Lib "SFmpq.dll" () As SFMPQVERSION
143
144' General error codes
145Public Const MPQ_ERROR_MPQ_INVALID As Long = &H85200065
146Public Const MPQ_ERROR_FILE_NOT_FOUND As Long = &H85200066
147Public Const MPQ_ERROR_DISK_FULL As Long = &H85200068 'Physical write file to MPQ failed. Not sure of exact meaning
148Public Const MPQ_ERROR_HASH_TABLE_FULL As Long = &H85200069
149Public Const MPQ_ERROR_ALREADY_EXISTS As Long = &H8520006A
150Public Const MPQ_ERROR_BAD_OPEN_MODE As Long = &H8520006C 'When MOAU_READ_ONLY is used without MOAU_OPEN_EXISTING
151
152Public Const MPQ_ERROR_COMPACT_ERROR As Long = &H85300001
153
154' MpqOpenArchiveForUpdate flags
155Public Const MOAU_CREATE_NEW As Long = &H0
156Public Const MOAU_CREATE_ALWAYS As Long = &H8 'Was wrongly named MOAU_CREATE_NEW
157Public Const MOAU_OPEN_EXISTING As Long = &H4
158Public Const MOAU_OPEN_ALWAYS As Long = &H20
159Public Const MOAU_READ_ONLY As Long = &H10 'Must be used with MOAU_OPEN_EXISTING
160Public Const MOAU_MAINTAIN_LISTFILE As Long = &H1
161
5f007675 162' MpqOpenArchiveForUpdateEx constants
163Public Const DEFAULT_BLOCK_SIZE As Long = 3 ' 512 << number = block size
164Public Const USE_DEFAULT_BLOCK_SIZE As Long = &HFFFF ' Use default block size that is defined internally
165
62046253 166' MpqAddFileToArchive flags
167Public Const MAFA_EXISTS As Long = &H80000000 'Will be added if not present
168Public Const MAFA_UNKNOWN40000000 As Long = &H40000000
169Public Const MAFA_MODCRYPTKEY As Long = &H20000
170Public Const MAFA_ENCRYPT As Long = &H10000
171Public Const MAFA_COMPRESS As Long = &H200
172Public Const MAFA_COMPRESS2 As Long = &H100
173Public Const MAFA_REPLACE_EXISTING As Long = &H1
174
175' MpqAddFileToArchiveEx compression flags
176Public Const MAFA_COMPRESS_STANDARD As Long = &H8 'Standard PKWare DCL compression
177Public Const MAFA_COMPRESS_DEFLATE As Long = &H2 'ZLib's deflate compression
178Public Const MAFA_COMPRESS_WAVE As Long = &H81 'Standard wave compression
179Public Const MAFA_COMPRESS_WAVE2 As Long = &H41 'Unused wave compression
180
181' Flags for individual compression types used for wave compression
182Public Const MAFA_COMPRESS_WAVECOMP1 As Long = &H80 'Main compressor for standard wave compression
183Public Const MAFA_COMPRESS_WAVECOMP2 As Long = &H40 'Main compressor for unused wave compression
184Public Const MAFA_COMPRESS_WAVECOMP3 As Long = &H1 'Secondary compressor for wave compression
185
186' ZLib deflate compression level constants (used with MpqAddFileToArchiveEx and MpqAddFileFromBufferEx)
187Public Const Z_NO_COMPRESSION As Long = 0
188Public Const Z_BEST_SPEED As Long = 1
189Public Const Z_BEST_COMPRESSION As Long = 9
190Public Const Z_DEFAULT_COMPRESSION As Long = (-1)
191
192' MpqAddWAVToArchive quality flags
193Public Const MAWA_QUALITY_HIGH As Long = 1
194Public Const MAWA_QUALITY_MEDIUM As Long = 0
195Public Const MAWA_QUALITY_LOW As Long = 2
196
197' SFileGetFileInfo flags
198Public Const SFILE_INFO_BLOCK_SIZE As Long = &H1 'Block size in MPQ
199Public Const SFILE_INFO_HASH_TABLE_SIZE As Long = &H2 'Hash table size in MPQ
200Public Const SFILE_INFO_NUM_FILES As Long = &H3 'Number of files in MPQ
201Public Const SFILE_INFO_TYPE As Long = &H4 'Is Long a file or an MPQ?
202Public Const SFILE_INFO_SIZE As Long = &H5 'Size of MPQ or uncompressed file
203Public Const SFILE_INFO_COMPRESSED_SIZE As Long = &H6 'Size of compressed file
204Public Const SFILE_INFO_FLAGS As Long = &H7 'File flags (compressed, etc.), file attributes if a file not in an archive
205Public Const SFILE_INFO_PARENT As Long = &H8 'Handle of MPQ that file is in
206Public Const SFILE_INFO_POSITION As Long = &H9 'Position of file pointer in files
207Public Const SFILE_INFO_LOCALEID As Long = &HA 'Locale ID of file in MPQ
208Public Const SFILE_INFO_PRIORITY As Long = &HB 'Priority of open MPQ
209Public Const SFILE_INFO_HASH_INDEX As Long = &HC 'Hash index of file in MPQ
210
211' SFileListFiles flags
212Public 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
213Public Const SFILE_LIST_ONLY_KNOWN As Long = &H2 ' Only list files that the function finds a name for
214Public Const SFILE_LIST_ONLY_UNKNOWN As Long = &H4 ' Only list files that the function does not find a name for
215
216Public Const SFILE_TYPE_MPQ As Long = &H1
217Public Const SFILE_TYPE_FILE As Long = &H2
218
219Public Const INVALID_HANDLE_VALUE As Long = -1
220
221Public Const FILE_BEGIN As Long = 0
222Public Const FILE_CURRENT As Long = 1
223Public Const FILE_END As Long = 2
224
225Public Const SFILE_OPEN_HARD_DISK_FILE As Long = &H0 'Open archive without regard to the drive type it resides on
226Public Const SFILE_OPEN_CD_ROM_FILE As Long = &H1 'Open the archive only if it is on a CD-ROM
227Public Const SFILE_OPEN_ALLOW_WRITE As Long = &H8000 'Open file with write access
228
229Public Const SFILE_SEARCH_CURRENT_ONLY As Long = &H0 'Used with SFileOpenFileEx; only the archive with the handle specified will be searched for the file
230Public Const SFILE_SEARCH_ALL_OPEN As Long = &H1 'SFileOpenFileEx will look through all open archives for the file
231
232Type FILELISTENTRY
233 dwFileExists As Long ' Nonzero if this entry is used
234 lcLocale As Long ' Locale ID of file
235 dwCompressedSize As Long ' Compressed size of file
236 dwFullSize As Long ' Uncompressed size of file
237 dwFlags As Long ' Flags for file
238 szFileName(259) As Byte
239End Type
240
241' Storm functions implemented by this library
242Declare Function SFileOpenArchive Lib "SFmpq.dll" (ByVal lpFileName As String, ByVal dwPriority As Long, ByVal dwFlags As Long, ByRef hMPQ As Long) As Boolean
243Declare Function SFileCloseArchive Lib "SFmpq.dll" (ByVal hMPQ As Long) As Boolean
244Declare Function SFileGetArchiveName Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
245Declare Function SFileOpenFile Lib "SFmpq.dll" (ByVal lpFileName As String, ByRef hFile As Long) As Boolean
246Declare Function SFileOpenFileEx Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String, ByVal dwSearchScope As Long, ByRef hFile As Long) As Boolean
247Declare Function SFileCloseFile Lib "SFmpq.dll" (ByVal hFile As Long) As Boolean
248Declare Function SFileGetFileSize Lib "SFmpq.dll" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
249Declare Function SFileGetFileArchive Lib "SFmpq.dll" (ByVal hFile As Long, ByRef hMPQ As Long) As Boolean
250Declare Function SFileGetFileName Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
251Declare Function SFileSetFilePointer Lib "SFmpq.dll" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lplDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
5f007675 252Declare 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
62046253 253Declare Function SFileSetLocale Lib "SFmpq.dll" (ByVal nNewLocale As Long) As Long
254Declare Function SFileGetBasePath Lib "SFmpq.dll" (ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
255Declare Function SFileSetBasePath Lib "SFmpq.dll" (ByVal lpNewBasePath As String) As Boolean
256
257' Extra storm-related functions
258Declare Function SFileGetFileInfo Lib "SFmpq.dll" (ByVal hFile As Long, ByVal dwInfoType As Long) As Long
259Declare Function SFileSetArchivePriority Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal dwPriority As Long) As Boolean
260Declare Function SFileFindMpqHeader Lib "SFmpq.dll" (ByVal hFile As Long) As Long
261Declare Function SFileListFiles Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileLists As String, ByRef lpListBuffer As FILELISTENTRY, ByVal dwFlags As Long) As Boolean
262
263' Archive editing functions implemented by this library
264Declare Function MpqOpenArchiveForUpdate Lib "SFmpq.dll" (ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwMaximumFilesInArchive As Long) As Long
265Declare Function MpqCloseUpdatedArchive Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal dwUnknown2 As Long) As Long
266Declare Function MpqAddFileToArchive Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpSourceFileName As String, ByVal lpDestFileName As String, ByVal dwFlags As Long) As Boolean
267Declare 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
268Declare Function MpqRenameFile Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpcOldFileName As String, ByVal lpcNewFileName As String) As Boolean
269Declare Function MpqDeleteFile Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String) As Boolean
270Declare Function MpqCompactArchive Lib "SFmpq.dll" (ByVal hMPQ As Long) As Boolean
271
272' Extra archive editing functions
5f007675 273Declare Function MpqOpenArchiveForUpdateEx Lib "SFmpq.dll" (ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwMaximumFilesInArchive As Long, ByVal dwBlockSize As Long) As Long
62046253 274Declare 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
5f007675 275Declare 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
276Declare 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
277Declare 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
62046253 278Declare Function MpqSetFileLocale Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String, ByVal nOldLocale As Long, ByVal nNewLocale As Long) As Boolean
279
280' These functions do nothing. They are only provided for
281' compatibility with MPQ extractors that use storm.
282Declare Function SFileDestroy Lib "SFmpq.dll" () As Boolean
283Declare Sub StormDestroy Lib "SFmpq.dll" ()
284
285' Returns 0 if the dll version is equal to the version your program was compiled
286' with, 1 if the dll is newer, -1 if the dll is older.
287Function SFMpqCompareVersion() As Long
288 Dim ExeVersion As SFMPQVERSION, DllVersion As SFMPQVERSION
289 With ExeVersion
290 .Major = 1
291 .Minor = 0
292 .Revision = 7
5f007675 293 .Subrevision = 4
62046253 294 End With
295 DllVersion = SFMpqGetVersion()
296 If DllVersion.Major > ExeVersion.Major Then
297 SFMpqCompareVersion = 1
298 Exit Function
299 ElseIf DllVersion.Major < ExeVersion.Major Then
300 SFMpqCompareVersion = -1
301 Exit Function
302 End If
303 If DllVersion.Minor > ExeVersion.Minor Then
304 SFMpqCompareVersion = 1
305 Exit Function
306 ElseIf DllVersion.Minor < ExeVersion.Minor Then
307 SFMpqCompareVersion = -1
308 Exit Function
309 End If
310 If DllVersion.Revision > ExeVersion.Revision Then
311 SFMpqCompareVersion = 1
312 Exit Function
313 ElseIf DllVersion.Revision < ExeVersion.Revision Then
314 SFMpqCompareVersion = -1
315 Exit Function
316 End If
317 If DllVersion.Subrevision > ExeVersion.Subrevision Then
318 SFMpqCompareVersion = 1
319 Exit Function
320 ElseIf DllVersion.Subrevision < ExeVersion.Subrevision Then
321 SFMpqCompareVersion = -1
322 Exit Function
323 End If
324 SFMpqCompareVersion = 0
325End Function
326