-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWAD3.h
117 lines (102 loc) · 2.55 KB
/
WAD3.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#pragma once
// WAD3 (Half-Life) Header and mip structs
#include <iostream>
#include <windows.h>
using namespace std;
#define WAD3_TYPE_MIP 0x43
#define WAD3_ID ('W' | 'A' << 8 | 'D' << 16 | '3' << 24)
#define GET_MIP_DATA_SIZE(WIDTH, HEIGHT) (sizeof(WAD3_MIP) + (WIDTH * HEIGHT) + (WIDTH * HEIGHT / 4) + (WIDTH * HEIGHT / 16) + (WIDTH * HEIGHT / 64))
////////////////////////////////////////////////////////////////////////////////
// WAD3 pseudo-structure:
/*
WAD3 Header
Mip section
First mip
Mip header
First mip (width * height)
Second mip (width * height / 4)
Third mip (width * height / 16)
Fourth mip (width * height / 64)
Palette size (WORD)
Palette (Palette size * 3)
Padding (WORD)
[...]
Last mip
Lump table
First lump entry
Lump header
[...]
Last lump entry
*/
////////////////////////////////////////////////////////////////////////////////
typedef struct
{
DWORD identification;
DWORD numlumps;
DWORD infotableofs; // Lump table
} WAD3_HEADER, *LPWAD3_HEADER;
typedef struct
{
DWORD filepos;
DWORD disksize;
DWORD size; // uncompressed
BYTE type;
BYTE compression;
BYTE pad1, pad2;
char name[16]; // must be null terminated
} WAD3_LUMP, *LPWAD3_LUMP;
typedef struct
{
char name[16];
DWORD width, height;
DWORD offsets[4]; // four mip maps stored
} WAD3_MIP, *LPWAD3_MIP;
extern void MapFile( LPCTSTR szFileName, LPVOID *pView, LPDWORD pdwFileSize);
extern int CorruptWAD3( LPCTSTR szErrorMessage, LPVOID lpView);
class CWADException
{
private:
DWORD m_dwError;
LPCTSTR m_szErrorMessage;
public:
CWADException()
{
m_szErrorMessage = NULL;
m_dwError = ::GetLastError();
}
CWADException( DWORD dwError)
{
m_szErrorMessage = NULL;
m_dwError = dwError;
}
CWADException( LPCTSTR szErrorMessage)
{
m_dwError = 0;
m_szErrorMessage = szErrorMessage;
}
~CWADException() {};
void PrintError()
{
if (m_dwError)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
m_dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
cout << "Whoops, something went wrong. GetLastError() = " << m_dwError << endl << (LPTSTR)lpMsgBuf << endl;
LocalFree( lpMsgBuf);
}
if (m_szErrorMessage)
{
cout << "Whoops, something went wrong. " << endl << m_szErrorMessage << endl;
}
}
};