VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsStormDLL"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'---------------------------------------------------------------------------------------
' Module    : clsStormDLL
' Date      : 6/23/2004
' Author    : LoRd[nK] (thevirushunter@hotmail.com)
' Purpose   : Class for handling functions exported from Blizzard's Storm.dll library
'---------------------------------------------------------------------------------------

Option Explicit

Private Declare Function SFileCloseArchive Lib "Storm.dll" Alias "#252" (ByVal hMpq As Long) As Boolean
Private Declare Function SFileCloseFile Lib "Storm.dll" Alias "#253" (ByVal hFile As Long) As Boolean
Private Declare Function SFileDestroy Lib "Storm.dll" Alias "#262" () As Boolean
Private Declare Function SFileGetFileArchive Lib "Storm.dll" Alias "#264" (ByVal hFile As Long, ByRef hMpq As Long) As Boolean
Private Declare Function SFileGetFileSize Lib "Storm.dll" Alias "#265" (ByVal hFile As Long, ByRef lpFileSizeHigh As Long) As Long
Private Declare Function SFileOpenArchive Lib "Storm.dll" Alias "#266" (ByVal lpFileName As String, ByVal dwPriority As Long, ByVal dwFlags As Long, ByRef hMpq As Long) As Boolean
Private Declare Function SFileOpenFile Lib "Storm.dll" Alias "#267" (ByVal lpFileName As String, ByRef hFile As Long) As Boolean
Private Declare Function SFileOpenFileEx Lib "Storm.dll" Alias "#268" (ByVal hMpq As Long, ByVal lpFileName As String, ByVal dwSearchScope As Long, ByRef hFile As Long) As Boolean
Private Declare Function SFileReadFile Lib "Storm.dll" Alias "#269" (ByVal hFile As Long, lpBuffer As Byte, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, lpOverlapped As Any) As Boolean
Private Declare Function SFileSetBasePath Lib "Storm.dll" Alias "#270" (ByVal lpNewBasePath As String) As Boolean
Private Declare Function SFileSetFilePointer Lib "Storm.dll" Alias "#271" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lplDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Declare Function SFileSetLocale Lib "Storm.dll" Alias "#272" (ByVal nNewLocale As Long) As Long
Private Declare Function SFileGetBasePath Lib "Storm.dll" Alias "#273" (ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
Private Declare Function SFileGetArchiveName Lib "Storm.dll" Alias "#275" (ByVal hMpq As Long, ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
Private Declare Function SFileGetFileName Lib "Storm.dll" Alias "#276" (ByVal hMpq As Long, ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
Private Declare Function SErrSetLastError Lib "Storm.dll" Alias "#465" (ByVal dwErrCode As Long) As Integer

Private Declare Function SMemCpy Lib "Storm.dll" Alias "#491" (ByRef src As Any, ByRef dst As Any, ByVal lng As Integer) As Integer
Private Declare Function SMemZero Lib "Storm.dll" Alias "#494" (ByRef buf As Any, ByVal count As Integer) As Integer

Private Declare Function SStrLen Lib "Storm.dll" Alias "#506" (ByVal str As String) As Integer
Private Declare Function SStrUpr Lib "Storm.dll" Alias "#510" (ByVal str As String) As Long
Private Declare Function SStrLwr Lib "Storm.dll" Alias "#579" (ByVal str As String) As Long
Private Declare Function SStrCpy Lib "Storm.dll" Alias "#501" (ByRef dst As String, ByRef src As String, ByVal count As Integer) As Long

Private Declare Function GetUserDefaultLangID Lib "Kernel32.dll" () As Long

Public Function ExtractFile(ByVal strArchiveName As String, ByVal strArchivedFile As String, ByVal strFileName As String) As Boolean
Dim hMpq As Long
Dim hFile As Long
Dim handle As Long
Dim nError As Long
Dim szBuffer() As Byte
Dim dwBytes As Long
Dim lngSize As Long

Call SFileSetLocale(&H409)
Call SFileDestroy
nError = (SFileOpenArchive(strArchiveName, 0, 0, hMpq))
If nError = False Then GoTo ERROR_HANDLER

nError = (SFileOpenFileEx(hMpq, strArchivedFile, 0, hFile))
If nError = False Then GoTo ERROR_HANDLER

lngSize = (SFileGetFileSize(hFile, 0))
If lngSize = &HFFFFFFFF Then GoTo ERROR_HANDLER

ReDim szBuffer(0 To lngSize)
Open strFileName For Binary Access Write As #1

nError = SFileReadFile(hFile, szBuffer(0), lngSize, dwBytes, vbNullString)
If nError = False Or dwBytes = 0 Then GoTo ERROR_HANDLER

Put #1, , szBuffer

Close #1
Call SFileCloseFile(hFile)
Call SFileCloseArchive(hMpq)
Exit Function

ERROR_HANDLER:
    Close #1
    Call SFileCloseFile(hFile)
    Call SFileCloseArchive(hMpq)
    Exit Function
End Function

