forked from diasurgical/devilution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture.cpp
More file actions
210 lines (194 loc) · 4.75 KB
/
capture.cpp
File metadata and controls
210 lines (194 loc) · 4.75 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//HEADER_GOES_HERE
#include "../types.h"
//----- (0040311B) --------------------------------------------------------
void __cdecl CaptureScreen()
{
int v4; // edi
PALETTEENTRY palette[256]; // [esp+0h] [ebp-508h]
char FileName[260]; // [esp+400h] [ebp-108h]
HANDLE hObject; // [esp+504h] [ebp-4h]
hObject = CaptureFile(FileName);
if ( hObject != (HANDLE)-1 )
{
DrawAndBlit();
lpDDPalette->GetEntries(0, 0, 256, palette);
RedPalette(palette);
dx_lock_mutex();
v4 = CaptureHdr(hObject, 640, 480);
if ( v4 )
{
v4 = CapturePix(hObject, 640, 480, 768, gpBuffer->row[0].pixels);
if ( v4 )
{
v4 = CapturePal(hObject, palette);
}
}
dx_unlock_mutex();
CloseHandle(hObject);
if ( !v4 )
DeleteFileA(FileName);
Sleep(300);
lpDDPalette->SetEntries(0, 0, 256, palette);
}
}
// 40311B: could not find valid save-restore pair for ebx
// 40311B: could not find valid save-restore pair for edi
// 40311B: could not find valid save-restore pair for esi
//----- (00403204) --------------------------------------------------------
bool __fastcall CaptureHdr(HANDLE hFile, short width, int height)
{
short v3; // si
HANDLE v4; // ebx
PCXHeader Buffer; // [esp+Ch] [ebp-84h]
DWORD lpNumBytes; // [esp+8Ch] [ebp-4h]
v3 = width;
v4 = hFile;
memset(&Buffer, 0, 0x80u);
Buffer.xmax = v3 - 1;
Buffer.vertRes = height;
Buffer.manufacturer = 10;
Buffer.version = 5;
Buffer.encoding = 1;
Buffer.bitsPerPixel = 8;
Buffer.ymax = height - 1;
Buffer.horzRes = v3;
Buffer.numColorPlanes = 1;
Buffer.bytesPerScanLine = v3;
return WriteFile(v4, &Buffer, 0x80u, &lpNumBytes, NULL) && lpNumBytes == 128;
}
//----- (00403294) --------------------------------------------------------
bool __fastcall CapturePal(HANDLE hFile, PALETTEENTRY *palette)
{
BYTE *v2; // eax
char *v3; // esi
signed int v4; // edx
char Buffer[772]; // [esp+8h] [ebp-308h]
DWORD lpNumBytes; // [esp+30Ch] [ebp-4h]
v2 = &palette->peBlue;
Buffer[0] = 12;
v3 = &Buffer[2];
v4 = 256;
do
{
*(v3 - 1) = *(v2 - 2);
*v3 = *(v2 - 1);
v3[1] = *v2;
v2 += 4;
v3 += 3;
--v4;
}
while ( v4 );
return WriteFile(hFile, Buffer, 0x301u, &lpNumBytes, 0) && lpNumBytes == 769;
}
//----- (004032FD) --------------------------------------------------------
bool __fastcall CapturePix(HANDLE hFile, short width, short height, short stride, char *pixels)
{
int v5; // esi
char *v6; // edi
char *v7; // eax
int v8; // ebx
DWORD lpNumBytes; // [esp+Ch] [ebp-8h]
HANDLE hFilea; // [esp+10h] [ebp-4h]
v5 = (unsigned short)width;
hFilea = hFile;
v6 = (char *)DiabloAllocPtr(2 * (unsigned short)width);
do
{
if ( !height )
{
mem_free_dbg(v6);
return 1;
}
*(_DWORD *)&height = height + 0xFFFF;
v7 = CaptureEnc(pixels, v6, v5);
pixels += (unsigned short)stride;
v8 = v7 - v6;
}
while ( WriteFile(hFilea, v6, v7 - v6, &lpNumBytes, 0) && lpNumBytes == v8 );
return 0;
}
//----- (0040336A) --------------------------------------------------------
char *__fastcall CaptureEnc(char *src, char *dst, int width)
{
int v3; // esi
char v4; // bl
signed int v5; // eax
v3 = width;
do
{
v4 = *src++;
v5 = 1;
--v3;
if ( v4 == *src )
{
do
{
if ( v5 >= 63 )
break;
if ( !v3 )
break;
++v5;
--v3;
++src;
}
while ( v4 == *src );
if ( v5 > 1 )
goto LABEL_13;
}
if ( (unsigned char)v4 > 0xBFu )
LABEL_13:
*dst++ = v5 | 0xC0;
*dst++ = v4;
}
while ( v3 );
return dst;
}
//----- (004033A8) --------------------------------------------------------
HANDLE __fastcall CaptureFile(char *dst_path)
{
char *v1; // edi
__int32 v2; // esi
int v3; // eax
int v5; // [esp-4h] [ebp-18Ch]
struct _finddata_t v6; // [esp+Ch] [ebp-17Ch]
char v7[100]; // [esp+124h] [ebp-64h]
v1 = dst_path;
memset(v7, 0, 0x64u);
v2 = _findfirst("screen??.PCX", &v6);
if ( v2 != -1 )
{
do
{
if ( isdigit(v6.name[6]) )
{
if ( isdigit(v6.name[7]) )
v7[10 * v6.name[6] - 528 + v6.name[7]] = 1;
}
}
while ( !_findnext(v2, &v6) );
}
v3 = 0;
while ( v7[v3] )
{
if ( ++v3 >= 100 )
return (HANDLE)-1;
}
v5 = v3;
sprintf(v1, "screen%02d.PCX", v3);
return CreateFileA(v1, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
}
// 4033A8: using guessed type char var_64[100];
//----- (00403470) --------------------------------------------------------
void __fastcall RedPalette(PALETTEENTRY *pal)
{
int i; // eax
PALETTEENTRY red[256]; // [esp+Ch] [ebp-400h]
for(i = 0; i < 256; i++)
{
red[i].peRed = pal[i].peRed;
red[i].peGreen = 0;
red[i].peBlue = 0;
red[i].peFlags = 0;
}
lpDDPalette->SetEntries(0, 0, 256, red);
}