102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
screenshots.c
Go to the documentation of this file.
11
12// Original pcdogs.exe: 0x418b90
14{
15 char path[260];
16 int32_t number = 0;
17
18 for (;;)
19 {
20 String_FormatCRTString(path, "sshot%03d.bmp", number);
21 struct File_Handle *existing = CRT_fopen(path, "rb");
22 if (!existing)
23 break;
24
25 ++number;
26 CRT_fclose(existing);
27 }
28
29 String_FormatCRTString(path, "sshot%03d.bmp", number);
31}
32
33// Original pcdogs.exe: 0x418bf0
34uint8_t *Graphics_ConvertSurface565ToBGR24(IDirectDrawSurface7 *surface)
35{
36 DDSURFACEDESC2 desc = {0};
37 desc.dwSize = sizeof(desc);
38 surface->lpVtbl->Lock(surface, NULL, &desc, DDLOCK_WAIT, NULL);
39
40 const uint16_t *pixels = desc.lpSurface;
41 const int32_t pitch = desc.lPitch / (int32_t)sizeof(*pixels);
42 uint8_t *output = &g_screenshotBuffer;
43
44 /* Retail starts at source row 480 and ends at row 1. */
45 for (int32_t y = GRAPHICS_DEFAULT_HEIGHT; y > 0; --y)
46 {
47 const uint16_t *row = pixels + y * pitch;
48 for (int32_t x = 0; x < GRAPHICS_DEFAULT_WIDTH; ++x)
49 {
50 *output++ = (uint8_t)((row[x] & 31) << 3);
51 *output++ = (uint8_t)(((row[x] >> 5) & 63) << 2);
52 *output++ = (uint8_t)((row[x] >> 11) << 3);
53 }
54 }
55
56 return &g_screenshotBuffer;
57}
58
59// Original pcdogs.exe: 0x418ce0
60void File_SaveScreenshot(const char *path)
61{
62 BITMAPINFOHEADER *info = LocalAlloc(LMEM_ZEROINIT, sizeof(*info));
63 info->biSize = sizeof(*info);
64 info->biWidth = GRAPHICS_DEFAULT_WIDTH;
65 info->biHeight = GRAPHICS_DEFAULT_HEIGHT;
66 info->biPlanes = 1;
67 info->biBitCount = 24;
68 info->biCompression = 0;
69 /* The BMP headers declare half the size of the pixel data written below. */
70 info->biSizeImage = GRAPHICS_DEFAULT_WIDTH * GRAPHICS_DEFAULT_HEIGHT * 3 / 2;
71 info->biClrImportant = 0;
72
75 HANDLE file = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_NONE, NULL,
77 if (file == INVALID_HANDLE_VALUE)
78 return;
79
80 struct PCDOGS_BitmapFileHeader header = {
81 .bfType = 0x4d42,
82 .bfSize = sizeof(header) + info->biSize + info->biSizeImage,
83 .bfOffBits = sizeof(header) + info->biSize};
84 DWORD written;
85 if (WriteFile(file, &header, sizeof(header), &written, NULL) &&
86 WriteFile(file, info, sizeof(*info), &written, NULL) &&
87 WriteFile(file, &g_screenshotBuffer, GRAPHICS_DEFAULT_WIDTH * GRAPHICS_DEFAULT_HEIGHT * 3, &written, NULL))
88 CloseHandle(file);
89}
#define GRAPHICS_DEFAULT_WIDTH
Definition constants.h:25
#define GRAPHICS_DEFAULT_HEIGHT
Definition constants.h:26
HRESULT DDraw_UnlockSurface(IDirectDrawSurface7 *surface)
#define g_ddrawBackBuffer
Definition globals.h:222
#define FILE_SHARE_NONE
Definition enums.h:202
@ CREATE_ALWAYS
Definition enums.h:44
#define FILE_ATTRIBUTE_NORMAL
Definition enums.h:80
int32_t CRT_fclose(struct File_Handle *stream)
Definition stdio.c:80
struct File_Handle * CRT_fopen(char const *filename, char const *mode)
Definition stdio.c:134
int32_t String_FormatCRTString(char *buffer, char const *format,...)
Definition formatting.c:18
void File_SaveScreenshot(const char *path)
Definition screenshots.c:60
void Graphics_TakeScreenshot(void)
Definition screenshots.c:13
uint8_t * Graphics_ConvertSurface565ToBGR24(IDirectDrawSurface7 *surface)
Definition screenshots.c:34
#define g_screenshotBuffer
Definition values.h:804
#define LMEM_ZEROINIT