Add FIX_MAJOR_BUGS option

This one specifically fixes bugs that either invoke undefined
behaviour or cause memory leaks. Essentially, they affect stability.
Bugs that just affect gameplay will remain covered by FIX_BUGS.
This commit is contained in:
Clownacy 2020-09-03 21:05:14 +01:00
parent e43160825e
commit 0c367cecf7
19 changed files with 51 additions and 40 deletions

View file

@ -14,6 +14,7 @@ set(ASSETS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets")
option(JAPANESE "Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)" OFF) option(JAPANESE "Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)" OFF)
option(FIX_BUGS "Fix various bugs in the game" OFF) option(FIX_BUGS "Fix various bugs in the game" OFF)
option(FIX_MAJOR_BUGS "Fix bugs that invoke undefined behaviour or cause memory leaks" OFF)
option(DEBUG_SAVE "Re-enable the dummied-out 'Debug Save' option, and the ability to drag-and-drop save files onto the window" OFF) option(DEBUG_SAVE "Re-enable the dummied-out 'Debug Save' option, and the ability to drag-and-drop save files onto the window" OFF)
option(LTO "Enable link-time optimisation" OFF) option(LTO "Enable link-time optimisation" OFF)
@ -169,6 +170,10 @@ if(FIX_BUGS)
target_compile_definitions(CSE2 PRIVATE FIX_BUGS) target_compile_definitions(CSE2 PRIVATE FIX_BUGS)
endif() endif()
if(FIX_BUGS OR FIX_MAJOR_BUGS)
target_compile_definitions(CSE2 PRIVATE FIX_MAJOR_BUGS)
endif()
if(DEBUG_SAVE) if(DEBUG_SAVE)
target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE) target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE)
endif() endif()

View file

@ -26,7 +26,11 @@ endif
FILENAME ?= $(FILENAME_DEF) FILENAME ?= $(FILENAME_DEF)
ifeq ($(FIX_BUGS), 1) ifeq ($(FIX_BUGS), 1)
ALL_CXXFLAGS += -DFIX_BUGS ALL_CXXFLAGS += -DFIX_BUGS -DFIX_MAJOR_BUGS
else
ifeq ($(FIX_MAJOR_BUGS), 1)
ALL_CXXFLAGS += -DFIX_MAJOR_BUGS
endif
endif endif
ifeq ($(DEBUG_SAVE), 1) ifeq ($(DEBUG_SAVE), 1)

View file

@ -82,6 +82,7 @@ Name | Function
--------|-------- --------|--------
`-DJAPANESE=ON` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation) `-DJAPANESE=ON` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)
`-DFIX_BUGS=ON` | Fix various bugs in the game `-DFIX_BUGS=ON` | Fix various bugs in the game
`-DFIX_MAJOR_BUGS=ON` | Fix bugs that invoke undefined behaviour or cause memory leaks
`-DDEBUG_SAVE=ON` | Re-enable [the dummied-out 'Debug Save' option](https://tcrf.net/Cave_Story#Debug_Save), and the ability to drag-and-drop save files onto the window `-DDEBUG_SAVE=ON` | Re-enable [the dummied-out 'Debug Save' option](https://tcrf.net/Cave_Story#Debug_Save), and the ability to drag-and-drop save files onto the window
`-DLTO=ON` | Enable link-time optimisation `-DLTO=ON` | Enable link-time optimisation
`-DMSVC_LINK_STATIC_RUNTIME=ON` | Link the static MSVC runtime library, to reduce the number of required DLL files (Visual Studio only) `-DMSVC_LINK_STATIC_RUNTIME=ON` | Link the static MSVC runtime library, to reduce the number of required DLL files (Visual Studio only)
@ -108,6 +109,7 @@ Name | Function
--------|-------- --------|--------
`JAPANESE=1` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation) `JAPANESE=1` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)
`FIX_BUGS=1` | Fix various bugs in the game `FIX_BUGS=1` | Fix various bugs in the game
`FIX_MAJOR_BUGS=1` | Fix bugs that invoke undefined behaviour or cause memory leaks
`DEBUG_SAVE=1` | Re-enable [the dummied-out 'Debug Save' option](https://tcrf.net/Cave_Story#Debug_Save), and the ability to drag-and-drop save files onto the window `DEBUG_SAVE=1` | Re-enable [the dummied-out 'Debug Save' option](https://tcrf.net/Cave_Story#Debug_Save), and the ability to drag-and-drop save files onto the window
`RELEASE=1` | Compile a release build (optimised, stripped, etc.) `RELEASE=1` | Compile a release build (optimised, stripped, etc.)
`STATIC=1` | Produce a statically-linked executable (so you don't need to bundle DLL files) `STATIC=1` | Produce a statically-linked executable (so you don't need to bundle DLL files)

View file

@ -36,7 +36,7 @@ BOOL InitBack(const char *fName, int type)
// Check if this is a valid bitmap file // 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 (bmp_header_buffer[0] != 0x4D42) // 'MB' (we use hex here to prevent a compiler warning)
{ {
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
// The original game forgets to close fp // The original game forgets to close fp
fclose(fp); fclose(fp);
#endif #endif

View file

@ -1644,7 +1644,7 @@ void ActBullet_Edge(BULLET *bul)
if (bul->ani_no > 4) if (bul->ani_no > 4)
{ {
bul->cond = 0; bul->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rcLeft' and 'rcRight', even though it's now too high return; // The code below will use 'ani_no' to access 'rcLeft' and 'rcRight', even though it's now too high
#endif #endif
} }
@ -2182,7 +2182,7 @@ void ActBullet_SpurTail(BULLET *bul, int level)
if (bul->ani_no > 2) if (bul->ani_no > 2)
{ {
bul->cond = 0; bul->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // Avoid accessing the RECT arrays with an out-of-bounds index return; // Avoid accessing the RECT arrays with an out-of-bounds index
#endif #endif
} }

View file

@ -105,7 +105,7 @@ void ActCaret01(CARET *crt)
if (++crt->ani_no > 3) if (++crt->ani_no > 3)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rcLeft' and 'rcRight', even though it's now too high return; // The code below will use 'ani_no' to access 'rcLeft' and 'rcRight', even though it's now too high
#endif #endif
} }
@ -155,7 +155,7 @@ void ActCaret02(CARET *crt)
if (crt->ani_no > 3) if (crt->ani_no > 3)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect_left', even though it's now too high return; // The code below will use 'ani_no' to access 'rect_left', even though it's now too high
#endif #endif
} }
@ -173,7 +173,7 @@ void ActCaret02(CARET *crt)
if (crt->ani_no > 3) if (crt->ani_no > 3)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect_right', even though it's now too high return; // The code below will use 'ani_no' to access 'rect_right', even though it's now too high
#endif #endif
} }
@ -208,7 +208,7 @@ void ActCaret03(CARET *crt)
if (++crt->ani_no > 3) if (++crt->ani_no > 3)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect', even though it's now too high return; // The code below will use 'ani_no' to access 'rect', even though it's now too high
#endif #endif
} }
@ -242,7 +242,7 @@ void ActCaret04(CARET *crt)
if (++crt->ani_no > 2) if (++crt->ani_no > 2)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect', even though it's now too high return; // The code below will use 'ani_no' to access 'rect', even though it's now too high
#endif #endif
} }
@ -273,7 +273,7 @@ void ActCaret05(CARET *crt)
if (crt->ani_no > 6) if (crt->ani_no > 6)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect', even though it's now too high return; // The code below will use 'ani_no' to access 'rect', even though it's now too high
#endif #endif
} }
@ -306,7 +306,7 @@ void ActCaret07(CARET *crt)
if (++crt->ani_no > 6) if (++crt->ani_no > 6)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rcLeft', even though it's now too high return; // The code below will use 'ani_no' to access 'rcLeft', even though it's now too high
#endif #endif
} }
@ -432,7 +432,7 @@ void ActCaret11(CARET *crt)
if (++crt->ani_no > 6) if (++crt->ani_no > 6)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rcRight', even though it's now too high return; // The code below will use 'ani_no' to access 'rcRight', even though it's now too high
#endif #endif
} }
@ -456,7 +456,7 @@ void ActCaret12(CARET *crt)
if (++crt->ani_no > 1) if (++crt->ani_no > 1)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rcLeft', even though it's now too high return; // The code below will use 'ani_no' to access 'rcLeft', even though it's now too high
#endif #endif
} }
@ -531,7 +531,7 @@ void ActCaret14(CARET *crt)
if (++crt->ani_no > 4) if (++crt->ani_no > 4)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect', even though it's now too high return; // The code below will use 'ani_no' to access 'rect', even though it's now too high
#endif #endif
} }
@ -557,7 +557,7 @@ void ActCaret15(CARET *crt)
if (++crt->ani_no > 3) if (++crt->ani_no > 3)
{ {
crt->cond = 0; crt->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rcLeft', even though it's now too high return; // The code below will use 'ani_no' to access 'rcLeft', even though it's now too high
#endif #endif
} }

View file

@ -273,7 +273,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no)
surf[surf_no]->SetColorKey(DDCKEY_SRCBLT, &ddcolorkey); surf[surf_no]->SetColorKey(DDCKEY_SRCBLT, &ddcolorkey);
surf[surf_no]->SetClipper(clipper); surf[surf_no]->SetClipper(clipper);
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
DeleteObject(handle); DeleteObject(handle);
#endif #endif
@ -414,7 +414,7 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no)
surf[surf_no]->SetColorKey(DDCKEY_SRCBLT, &ddcolorkey); surf[surf_no]->SetColorKey(DDCKEY_SRCBLT, &ddcolorkey);
surf[surf_no]->SetClipper(clipper); surf[surf_no]->SetClipper(clipper);
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
DeleteObject(handle); DeleteObject(handle);
#endif #endif

View file

@ -249,7 +249,7 @@ BOOL StartCreditScript(void)
fread(Credit.pData, 1, Credit.size, fp); fread(Credit.pData, 1, Credit.size, fp);
EncryptionBinaryData2((unsigned char*)Credit.pData, Credit.size); EncryptionBinaryData2((unsigned char*)Credit.pData, Credit.size);
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
// The original game forgot to close the file // The original game forgot to close the file
fclose(fp); fclose(fp);
#endif #endif

View file

@ -560,7 +560,7 @@ static int ModeAction(HWND hWnd)
ActBullet(); ActBullet();
ActCaret(); ActCaret();
MoveFrame3(); MoveFrame3();
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
// ActFlash uses frame_x and frame_y uninitialised // ActFlash uses frame_x and frame_y uninitialised
GetFramePosition(&frame_x, &frame_y); GetFramePosition(&frame_x, &frame_y);
#endif #endif

View file

@ -151,7 +151,7 @@ BOOL CALLBACK EnumDevices_Callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
directinput_objects->device = _joystick; directinput_objects->device = _joystick;
char string[0x100]; char string[0x100];
#ifdef FIX_BUGS #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(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]);
#else #else
sprintf(string, "DeviceGUID = %x\n", lpddi->guidInstance); // Tries to print a struct as an int sprintf(string, "DeviceGUID = %x\n", lpddi->guidInstance); // Tries to print a struct as an int

View file

@ -110,7 +110,7 @@ void DamageMyChar(int damage)
#ifdef FIX_BUGS #ifdef FIX_BUGS
if (!(g_GameFlags & 2)) if (!(g_GameFlags & 2))
#else #else
// I'm preeeetty sure this is a typo. The Linux port optimised it out. // I'm preeeetty sure this is a typo. The Linux port optimised this entire check out.
if (!(g_GameFlags | 2)) if (!(g_GameFlags | 2))
#endif #endif
return; return;
@ -272,7 +272,7 @@ void PutArmsEnergy(BOOL flash)
int lv = gArmsData[gSelectedArms].level - 1; int lv = gArmsData[gSelectedArms].level - 1;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
// When the player has no weapons, the default level is 0, which becomes -1. // When the player has no weapons, the default level is 0, which becomes -1.
// Catch it, and set it to 0 instead, so the following array-accesses aren't // Catch it, and set it to 0 instead, so the following array-accesses aren't
// out-of-bounds. // out-of-bounds.

View file

@ -70,7 +70,7 @@ BOOL LoadEvent(const char *path_event)
fread(code, 1, 4, fp); fread(code, 1, 4, fp);
if (memcmp(code, gPassPixEve, 3) != 0) if (memcmp(code, gPassPixEve, 3) != 0)
{ {
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
// The original game forgot to close the file here // The original game forgot to close the file here
fclose(fp); fclose(fp);
#endif #endif

View file

@ -59,7 +59,7 @@ void ActNpc001(NPCHAR *npc)
if (npc->xm < -0x600) if (npc->xm < -0x600)
npc->xm = -0x600; npc->xm = -0x600;
#else #else
// Limit speed (except pixel applied it to the X position) // Limit speed (except Pixel applied it to the X position)
if (npc->x < -0x600) if (npc->x < -0x600)
npc->x = -0x600; npc->x = -0x600;
#endif #endif

View file

@ -590,7 +590,7 @@ void ActNpc127(NPCHAR *npc)
if (++npc->ani_no > 2) if (++npc->ani_no > 2)
{ {
npc->cond = 0; npc->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rcH' and 'rcV', even though it's now too high return; // The code below will use 'ani_no' to access 'rcH' and 'rcV', even though it's now too high
#endif #endif
} }
@ -656,7 +656,7 @@ void ActNpc128(NPCHAR *npc)
if (++npc->ani_no > 4) if (++npc->ani_no > 4)
{ {
npc->cond = 0; npc->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rcLeft' and co., even though it's now too high return; // The code below will use 'ani_no' to access 'rcLeft' and co., even though it's now too high
#endif #endif
} }
@ -717,7 +717,7 @@ void ActNpc129(NPCHAR *npc)
if (++npc->ani_no > 2) if (++npc->ani_no > 2)
{ {
npc->cond = 0; npc->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect', even though it's now too high return; // The code below will use 'ani_no' to access 'rect', even though it's now too high
#endif #endif
} }

View file

@ -753,7 +753,7 @@ void ActNpc146(NPCHAR *npc)
{ {
SetDestroyNpChar(npc->x, npc->y, 0x1000, 8); SetDestroyNpChar(npc->x, npc->y, 0x1000, 8);
npc->cond = 0; npc->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect', even though it's now too high return; // The code below will use 'ani_no' to access 'rect', even though it's now too high
#endif #endif
} }

View file

@ -1429,7 +1429,7 @@ void ActNpc199(NPCHAR *npc)
if (npc->ani_no > 4) if (npc->ani_no > 4)
{ {
npc->cond = 0; npc->cond = 0;
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
return; // The code below will use 'ani_no' to access 'rect', even though it's now too high return; // The code below will use 'ani_no' to access 'rect', even though it's now too high
#endif #endif
} }

View file

@ -212,7 +212,7 @@ BOOL MakeSoundObject8(signed char *wavep, signed char track, signed char pipi)
if (hr != DS_OK) if (hr != DS_OK)
{ {
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
free(wp); // The updated Organya source code includes this fix free(wp); // The updated Organya source code includes this fix
#endif #endif
return FALSE; return FALSE;

View file

@ -165,7 +165,7 @@ BOOL LoadSoundObject(LPCSTR file_name, int no)
for (i = 0; i < 58; i++) for (i = 0; i < 58; i++)
fread(&check_box[i], sizeof(char), 1, fp); // Holy hell, this is inefficient fread(&check_box[i], sizeof(char), 1, fp); // Holy hell, this is inefficient
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
// The original code forgets to close 'fp' // The original code forgets to close 'fp'
if (check_box[0] != 'R' || check_box[1] != 'I' || check_box[2] != 'F' || check_box[3] != 'F') if (check_box[0] != 'R' || check_box[1] != 'I' || check_box[2] != 'F' || check_box[3] != 'F')
{ {
@ -186,7 +186,7 @@ BOOL LoadSoundObject(LPCSTR file_name, int no)
DWORD *wp; DWORD *wp;
wp = (DWORD*)malloc(file_size); // ファイルのワークスペースを作る (Create a file workspace) wp = (DWORD*)malloc(file_size); // ファイルのワークスペースを作る (Create a file workspace)
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
if (wp == NULL) if (wp == NULL)
{ {
fclose(fp); fclose(fp);
@ -211,7 +211,7 @@ BOOL LoadSoundObject(LPCSTR file_name, int no)
if (lpDS->CreateSoundBuffer(&dsbd, &lpSECONDARYBUFFER[no], NULL) != DS_OK) if (lpDS->CreateSoundBuffer(&dsbd, &lpSECONDARYBUFFER[no], NULL) != DS_OK)
{ {
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
free(wp); // The updated Organya source code includes this fix free(wp); // The updated Organya source code includes this fix
#endif #endif
return FALSE; return FALSE;
@ -225,7 +225,7 @@ BOOL LoadSoundObject(LPCSTR file_name, int no)
if (hr != DS_OK) if (hr != DS_OK)
{ {
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
free(wp); // The updated Organya source code includes this fix free(wp); // The updated Organya source code includes this fix
#endif #endif
return FALSE; return FALSE;

View file

@ -678,7 +678,7 @@ int TextScriptProc(void)
x = GetTextScriptNo(gTS.p_read + 9); x = GetTextScriptNo(gTS.p_read + 9);
gNumberTextScript[0] = x; gNumberTextScript[0] = x;
#ifndef FIX_BUGS #ifndef FIX_MAJOR_BUGS
// z is uninitialised. Probably a leftover from copypasting this from elsewhere. // z is uninitialised. Probably a leftover from copypasting this from elsewhere.
gNumberTextScript[1] = z; gNumberTextScript[1] = z;
#endif #endif
@ -898,7 +898,7 @@ int TextScriptProc(void)
x = GetTextScriptNo(gTS.p_read + 4); x = GetTextScriptNo(gTS.p_read + 4);
z = GetTextScriptNo(gTS.p_read + 9); z = GetTextScriptNo(gTS.p_read + 9);
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
// Some versions of the Waterway TSC script contain a bug: // Some versions of the Waterway TSC script contain a bug:
// <FLJ850:0111 // <FLJ850:0111
// This command *should* be... // This command *should* be...
@ -1007,7 +1007,7 @@ int TextScriptProc(void)
} }
else if (IS_COMMAND('S','P','S')) else if (IS_COMMAND('S','P','S'))
{ {
#ifdef FIX_BUGS #ifdef FIX_MAJOR_BUGS
SetNoise(2, 0); SetNoise(2, 0);
#else #else
// x is not initialised. This bug isn't too bad, since that parameter's not used when the first one is set to 2, but still. // x is not initialised. This bug isn't too bad, since that parameter's not used when the first one is set to 2, but still.