From 2882f6651afd799c3c2ffaf17676a944ecdfa6f4 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 17 Sep 2020 20:21:49 +0100 Subject: [PATCH 1/5] Apply some Windows types to InitBack Thanks, Cucky --- src/Back.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Back.cpp b/src/Back.cpp index c21fbb6f..5315a7ec 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -16,25 +16,24 @@ static unsigned long color_black; // TODO - Another function that has an incorrect stack frame BOOL InitBack(const char *fName, int type) { + char path[MAX_PATH]; + FILE *fp; + BITMAPFILEHEADER file_header; // The original names for these two variables are unknown. This ruins the stack frame layout. + BITMAPINFOHEADER info_header; + color_black = GetCortBoxColor(RGB(0, 0, 0x10)); // Unused. This may have once been used by background type 4 (the solid black background) // We're not actually loading the bitmap here - we're just reading its width/height and making sure it's really a BMP file - char path[MAX_PATH]; sprintf(path, "%s\\%s.pbm", gDataPath, fName); - FILE *fp = fopen(path, "rb"); + fp = fopen(path, "rb"); if (fp == NULL) return FALSE; - // This code is ridiculously platform-dependant: - // It should break on big-endian CPUs, and platforms where short isn't 16-bit and long isn't 32-bit. - unsigned short bmp_header_buffer[7]; // The original names for these variables are unknown. This ruins the stack frame layout. - unsigned long bmp_header_buffer2[10]; - - fread(bmp_header_buffer, 14, 1, fp); + fread(&file_header, sizeof(file_header), 1, fp); // Check if this is a valid bitmap file - if (bmp_header_buffer[0] != 0x4D42) // 'MB' (we use hex here to prevent a compiler warning) + if (file_header.bfType != 0x4D42) // 'MB' (we use hex here to prevent a compiler warning) { #ifdef FIX_MAJOR_BUGS // The original game forgets to close fp @@ -43,12 +42,12 @@ BOOL InitBack(const char *fName, int type) return FALSE; } - fread(bmp_header_buffer2, 40, 1, fp); + fread(&info_header, sizeof(info_header), 1, fp); fclose(fp); // Get bitmap width and height - gBack.partsW = bmp_header_buffer2[1]; - gBack.partsH = bmp_header_buffer2[2]; + gBack.partsW = info_header.biWidth; + gBack.partsH = info_header.biHeight; gBack.flag = TRUE; // This variable is otherwise unused From 527328c3037aeb76793ceedae311084ba9a49a9d Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 17 Sep 2020 20:46:32 +0100 Subject: [PATCH 2/5] Fix a typo --- src/Draw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index 7e7b57ad..8c028445 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -87,7 +87,7 @@ BOOL Flip_SystemTask(HWND hWnd) else timePrev += 20; - static RECT dst_rect; // TODO - Not the original vaiable name + static RECT dst_rect; // TODO - Not the original variable name GetWindowRect(hWnd, &dst_rect); dst_rect.left += client_x; dst_rect.top += client_y; From c0a6441bcba2de735322d7738cb2366b0820c424 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 17 Sep 2020 20:55:46 +0100 Subject: [PATCH 3/5] Fix another typo --- src/Draw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index 8c028445..6293a63e 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -746,7 +746,7 @@ BOOL out(int unknown) return TRUE; } -// TODO - Probably not the original variable name (this is an educated guess) +// TODO - Probably not the original function name (this is an educated guess) int RestoreSurfaces(void) { int s; From 3a3530252b40b29bb0933c227c6634c4170da9e9 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 17 Sep 2020 21:05:55 +0100 Subject: [PATCH 4/5] Document some leftover debug-related code --- src/Draw.cpp | 19 +++++++++---------- src/GenericLoad.cpp | 4 +++- src/Input.cpp | 15 +++++++++++---- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index 6293a63e..db2964fd 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -730,18 +730,17 @@ void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no) // Dummied-out log function // According to the Mac port, its name really is just "out". -BOOL out(int unknown) +BOOL out(int surface_identifier) { - char unknown2[0x100]; - int unknown3; - int unknown4; - int unknown5; + char str[0x100]; - (void)unknown; - (void)unknown2; - (void)unknown3; - (void)unknown4; - (void)unknown5; + // The actual name of these two variables are unknown + (void)surface_identifier; + (void)str; + + // There may have been some kind of 'OutputDebugStringA' call here, + // like the one in 'EnumDevices_Callback' in 'Input.cpp'. + // Pixel may have kept them wrapped in '#ifdef DEBUG' blocks. return TRUE; } diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index a72f5dc3..d64e6f42 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -295,6 +295,8 @@ BOOL LoadGenericData(void) char str[0x40]; sprintf(str, "PixTone = %d byte", pt_size); - // There must have been some kind of console print function here or something + // There must have once been a 'OutputDebugStringA' call here or something. + // See 'EnumDevices_Callback' in 'Input.cpp' for an example of this. + return TRUE; } diff --git a/src/Input.cpp b/src/Input.cpp index f2db63cd..5a32ab7b 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -150,13 +150,20 @@ BOOL CALLBACK EnumDevices_Callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) directinput_objects->device = _joystick; - char string[0x100]; + // This is interesting: there are at least two places in the game + // where it seems like there's meant to be a debug print just like + // this one: these are the 'out' function in 'Draw.cpp', and the + // 'LoadGenericData' function in 'GenericLoad.cpp'. + // Perhaps Pixel kept them wrapped in '#ifdef DEBUG' blocks, and + // simply forgot to do the same here. + + char str[0x100]; #ifdef FIX_MAJOR_BUGS - sprintf(string, "DeviceGUID = %08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", lpddi->guidInstance.Data1, lpddi->guidInstance.Data2, lpddi->guidInstance.Data3, lpddi->guidInstance.Data4[0], lpddi->guidInstance.Data4[1], lpddi->guidInstance.Data4[2], lpddi->guidInstance.Data4[3], lpddi->guidInstance.Data4[4], lpddi->guidInstance.Data4[5], lpddi->guidInstance.Data4[6], lpddi->guidInstance.Data4[7]); + sprintf(str, "DeviceGUID = %08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", lpddi->guidInstance.Data1, lpddi->guidInstance.Data2, lpddi->guidInstance.Data3, lpddi->guidInstance.Data4[0], lpddi->guidInstance.Data4[1], lpddi->guidInstance.Data4[2], lpddi->guidInstance.Data4[3], lpddi->guidInstance.Data4[4], lpddi->guidInstance.Data4[5], lpddi->guidInstance.Data4[6], lpddi->guidInstance.Data4[7]); #else - sprintf(string, "DeviceGUID = %x\n", lpddi->guidInstance); // Tries to print a struct as an int + sprintf(str, "DeviceGUID = %x\n", lpddi->guidInstance); // Tries to print a struct as an int #endif - OutputDebugStringA(string); + OutputDebugStringA(str); return DIENUM_STOP; } From 620a25d75c2a9a307543b5abf2612c2ea38d5967 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 17 Sep 2020 21:44:13 +0100 Subject: [PATCH 5/5] Made `out` ASM-accurate It just so happens that a path buffer and a FILE pointer both take up the right amount of stack space *and* have the correct stack frame ordering, so maybe this is actually what the original source code did. --- src/Draw.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index db2964fd..a08a4cd9 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -730,13 +730,15 @@ void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no) // Dummied-out log function // According to the Mac port, its name really is just "out". -BOOL out(int surface_identifier) +BOOL out(char surface_identifier) { - char str[0x100]; + // The actual name (and type) of these two variables are unknown + char path[MAX_PATH]; + FILE *fp; - // The actual name of these two variables are unknown (void)surface_identifier; - (void)str; + (void)path; + (void)fp; // There may have been some kind of 'OutputDebugStringA' call here, // like the one in 'EnumDevices_Callback' in 'Input.cpp'.