shithub: cstory

Download patch

ref: 3bac7674f40ac75bfe85b2cef4107443dc6560a9
parent: 5dd3a5dd2df7aed2814dc4f91a55d193ef62c86a
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 5 11:03:34 EDT 2019

Correct some WinAPI usage

All the broken stuff just happened to work on 32-bit, but would cause
MinGW-w64 to explode if you tried building as 64-bit.

I guess thanks to Microsoft keeping the basic C int types the same
size in 64-bit as they were in 32-bit, this branch compiles as 64-bit
just fine, despite Cave Story's many int-size dependencies.

--- a/src/Dialog.cpp
+++ b/src/Dialog.cpp
@@ -17,7 +17,7 @@
 	;
 
 // TODO - Inaccurate stack frame
-BOOL __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
+INT_PTR __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
 	char string_buffer[104];
 
@@ -56,7 +56,7 @@
 	return FALSE;
 }
 
-BOOL __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
+INT_PTR __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
 	switch (Msg)
 	{
@@ -98,7 +98,7 @@
 	return FALSE;
 }
 
-BOOL __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
+INT_PTR __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
 	char string[100];
 
@@ -129,7 +129,7 @@
 	return FALSE;
 }
 
-BOOL __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
+INT_PTR __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
 	switch (Msg)
 	{
--- a/src/Dialog.h
+++ b/src/Dialog.h
@@ -2,7 +2,7 @@
 
 #include "WindowsWrapper.h"
 
-BOOL __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
-BOOL __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
-BOOL __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
-BOOL __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
+INT_PTR __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
+INT_PTR __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
+INT_PTR __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
+INT_PTR __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
--- a/src/Generic.cpp
+++ b/src/Generic.cpp
@@ -99,58 +99,63 @@
 // TODO - Inaccurate stack frame
 BOOL OpenVolumeConfiguration(HWND hWnd)
 {
+#ifdef FIX_BUGS
 	char path[MAX_PATH];
 	char path2[MAX_PATH];
 	char path3[MAX_PATH];
-#ifdef FIX_BUGS
-	char path4[MAX_PATH];
-	char path5[MAX_PATH];
-#endif
-	int error1;
-	int error2;
-#ifdef FIX_BUGS
-	int error3;
-	int error4;
-#endif
+	INT_PTR error;
 	size_t i;
 
 	GetSystemDirectoryA(path, sizeof(path));
-	sprintf(path2, "%s\\Sndvol32.exe", path);
-#ifdef FIX_BUGS
-	sprintf(path4, "%s\\Sndvol.exe", path);
-#endif
+	GetSystemDirectoryA(path2, sizeof(path2));
 
-	i = strlen(path);
-	while (path[i] != '\\')
+	i = strlen(path2);
+	while (path2[i] != '\\')
 		--i;
 
-	path[i] = '\0';
-	sprintf(path3, "%s\\Sndvol32.exe", path);
-#ifdef FIX_BUGS
-	sprintf(path5, "%s\\Sndvol.exe", path);
-#endif
+	path2[i] = '\0';
 
-#ifdef FIX_BUGS
-	error1 = (int)ShellExecuteA(hWnd, "open", path2, NULL, NULL, SW_SHOW);
-	if (error1 > 32)
+	sprintf(path3, "%s\\Sndvol32.exe", path);
+	error = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
+	if (error > 32)
 		return TRUE;
 
-	error2 = (int)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
-	if (error2 > 32)
+	sprintf(path3, "%s\\Sndvol32.exe", path2);
+	error = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
+	if (error > 32)
 		return TRUE;
 
-	error3 = (int)ShellExecuteA(hWnd, "open", path4, NULL, NULL, SW_SHOW);
-	if (error3 > 32)
+	sprintf(path3, "%s\\Sndvol.exe", path);
+	error = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
+	if (error > 32)
 		return TRUE;
 
-	error4 = (int)ShellExecuteA(hWnd, "open", path5, NULL, NULL, SW_SHOW);
-	if (error4 > 32)
+	sprintf(path3, "%s\\Sndvol.exe", path2);
+	error = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
+	if (error > 32)
 		return TRUE;
 
 	return FALSE;
 #else
-	error1 = (int)ShellExecuteA(hWnd, "open", path2, NULL, NULL, SW_SHOW);
-	error2 = (int)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
+	char path[MAX_PATH];
+	char path2[MAX_PATH];
+	char path3[MAX_PATH];
+	INT_PTR error1;
+	INT_PTR error2;
+	size_t i;
+
+	GetSystemDirectoryA(path, sizeof(path));
+	sprintf(path2, "%s\\Sndvol32.exe", path);
+
+	i = strlen(path);
+	while (path[i] != '\\')
+		--i;
+
+	path[i] = '\0';
+	sprintf(path3, "%s\\Sndvol32.exe", path);
+
+	error1 = (INT_PTR)ShellExecuteA(hWnd, "open", path2, NULL, NULL, SW_SHOW);
+	error2 = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
 
 	if (error1 <= 32 && error2 <= 32)
 		return FALSE;