aboutsummaryrefslogtreecommitdiff
path: root/storm_dll/storm_test.cpp
blob: 397c4ddff93009483cbca063a8d6cdc5d7f71806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*****************************************************************************/
/* Storm_test.cpp                         Copyright (c) Ladislav Zezula 2014 */
/*---------------------------------------------------------------------------*/
/* Test module for storm.dll (original Blizzard MPQ dynalic library          */
/*---------------------------------------------------------------------------*/
/*   Date    Ver   Who  Comment                                              */
/* --------  ----  ---  -------                                              */
/* 24.08.14  1.00  Lad  The first version of Storm_test.cpp                  */
/*****************************************************************************/

#define _CRT_NON_CONFORMING_SWPRINTFS
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>

#ifdef _MSC_VER
#include <crtdbg.h>
#endif

#define STORM_ALTERNATE_NAMES               // Use Storm* prefix for functions
#include "storm.h"                          // Header file for Storm.dll

//-----------------------------------------------------------------------------
// Main

int main(int argc, char * argv[])
{
    LPCSTR szArchiveName;
    LPCSTR szFileName;
    LPCSTR szFormat;
    HANDLE hMpq = NULL;
    HANDLE hFile = NULL;
    BYTE Buffer[0x100];
    DWORD dwBytesRead = 0;
    DWORD dwFileSize = 0;
    BOOL bResult;

    // Check parameters
    if(argc != 3)
    {
        printf("Error: Missing MPQ or file name\n");
        return 3;
    }

    // Get both arguments
    SetLastError(ERROR_SUCCESS);
    szArchiveName = argv[1];
    szFileName = argv[2];

    // Put Storm.dll to the current folder before running this
    printf("[*] Opening archive '%s' ...\n", szArchiveName);
    if(StormOpenArchive(szArchiveName, 0, 0, &hMpq))
    {
        printf("[*] Opening file '%s' ...\n", szFileName);
        if(StormOpenFileEx(hMpq, "staredit\\scenario.chk", 0, &hFile))
        {
            printf("[*] Retrieving file size ... ");
            dwFileSize = StormGetFileSize(hFile, NULL);
            szFormat = (dwFileSize == INVALID_FILE_SIZE) ? ("(invalid)\n") : ("(%u bytes)\n");
            printf(szFormat, dwFileSize);

            printf("[*] Moving to begin of the file ...\n");
            StormSetFilePointer(hFile, 0, NULL, FILE_BEGIN);
            
            printf("[*] Reading file ... ");
            bResult = StormReadFile(hFile, Buffer, sizeof(Buffer), &dwBytesRead, NULL);
            szFormat = (bResult == FALSE) ? ("(error %u)\n") : ("(OK)\n");
            printf(szFormat, GetLastError());
            
            printf("[*] Closing file ...\n");
            StormCloseFile(hFile);
        }

        printf("[*] Closing archive ...\n");
        StormCloseArchive(hMpq);
    }

    printf("Done.\n\n");
    return 0;
}