From 295dc35429d6a108fd1a1026557d636e3b06f504 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 10 Apr 2020 23:08:23 +0200 Subject: [PATCH 01/19] Renable delete operator This aligns the first instructions, now that we only target C++ it's we can safly enable it. Should be moved to storm.h. --- Source/appfat.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/appfat.cpp b/Source/appfat.cpp index 64a14846a..3a718c08b 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -13,12 +13,12 @@ BOOL terminating; int cleanup_thread_id; // delete overloads the delete operator. -//void operator delete(void *ptr) -//{ -// if (ptr != NULL) { -// SMemFree(ptr, "delete", -1, 0); -// } -//} +void __cdecl operator delete(void *ptr) +{ + if (ptr != NULL) { + SMemFree(ptr, "delete", -1, 0); + } +} void TriggerBreak() { From 67d659448e102370c41122862f1c0179fd56872c Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 10 Apr 2020 23:09:03 +0200 Subject: [PATCH 02/19] Correct build options Disable minimal rebuild. Target Pentium --- MakefileVC | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MakefileVC b/MakefileVC index 0c768814a..24c0cdc5c 100644 --- a/MakefileVC +++ b/MakefileVC @@ -37,7 +37,7 @@ else VC6_LINK = wine $(VC6_BIN_DIR)/link.exe endif -CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /FD /Gr /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fp"Diablo.pch" /YX /Gm /Zi /FAs +CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /FD /Gr /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fp"Diablo.pch" /YX /G5 /Zi /FAs LINKFLAGS=/nologo /subsystem:windows /machine:I386 /incremental:no ifeq ($(SPAWN),1) From f4c181dd7099fddef4cf2d76b5d5517b130eb2ad Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 10 Apr 2020 23:11:06 +0200 Subject: [PATCH 03/19] Correct size of app_fatal The call to ExitProcess(1) can be seen in the original ASM, but still isen't emitted by the compiler for our code :/ --- Source/appfat.cpp | 1 + comparer-config/diablo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/appfat.cpp b/Source/appfat.cpp index 3a718c08b..c319e04d2 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -484,6 +484,7 @@ void __cdecl app_fatal(const char *pszFmt, ...) init_cleanup(FALSE); exit(1); + ExitProcess(1); } void MsgBox(const char *pszFmt, va_list va) diff --git a/comparer-config/diablo.toml b/comparer-config/diablo.toml index d021375de..e94444af4 100644 --- a/comparer-config/diablo.toml +++ b/comparer-config/diablo.toml @@ -30,7 +30,7 @@ size = 0xD [[func]] name = "app_fatal" addr = 0x401947 -size = 0x24 +size = 0x2E [[func]] name = "MsgBox" From af7db10bacf05800d7619b8937d1453f048b4851 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 10 Apr 2020 23:18:20 +0200 Subject: [PATCH 04/19] Correct switch order for TraceErrorDD This fixes the jump table at the end of the function https://github.com/galaxyhaxz/devastation/blob/master/FIXES/appfat.cpp --- Source/appfat.cpp | 374 +++++++++++++++++++++++----------------------- 1 file changed, 187 insertions(+), 187 deletions(-) diff --git a/Source/appfat.cpp b/Source/appfat.cpp index c319e04d2..90ad6f0ae 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -96,188 +96,161 @@ void TraceErrorDD(HRESULT hError, char *pszBuffer, DWORD dwMaxChars) const char *szError; switch (hError) { - case DDERR_CANTPAGEUNLOCK: - szError = "DDERR_CANTPAGEUNLOCK"; - break; - case DDERR_NOTPAGELOCKED: - szError = "DDERR_NOTPAGELOCKED"; - break; case DD_OK: szError = "DD_OK"; break; - case DDERR_CANTPAGELOCK: - szError = "DDERR_CANTPAGELOCK"; + case DDERR_ALREADYINITIALIZED: + szError = "DDERR_ALREADYINITIALIZED"; break; case DDERR_BLTFASTCANTCLIP: szError = "DDERR_BLTFASTCANTCLIP"; break; - case DDERR_NOBLTHW: - szError = "DDERR_NOBLTHW"; - break; - case DDERR_NODDROPSHW: - szError = "DDERR_NODDROPSHW"; - break; - case DDERR_OVERLAYNOTVISIBLE: - szError = "DDERR_OVERLAYNOTVISIBLE"; - break; - case DDERR_NOOVERLAYDEST: - szError = "DDERR_NOOVERLAYDEST"; - break; - case DDERR_INVALIDPOSITION: - szError = "DDERR_INVALIDPOSITION"; - break; - case DDERR_NOTAOVERLAYSURFACE: - szError = "DDERR_NOTAOVERLAYSURFACE"; + case DDERR_CANNOTATTACHSURFACE: + szError = "DDERR_CANNOTATTACHSURFACE"; break; - case DDERR_EXCLUSIVEMODEALREADYSET: - szError = "DDERR_EXCLUSIVEMODEALREADYSET"; + case DDERR_CANNOTDETACHSURFACE: + szError = "DDERR_CANNOTDETACHSURFACE"; break; - case DDERR_NOTFLIPPABLE: - szError = "DDERR_NOTFLIPPABLE"; + case DDERR_CANTCREATEDC: + szError = "DDERR_CANTCREATEDC"; break; case DDERR_CANTDUPLICATE: szError = "DDERR_CANTDUPLICATE"; break; - case DDERR_NOTLOCKED: - szError = "DDERR_NOTLOCKED"; - break; - case DDERR_CANTCREATEDC: - szError = "DDERR_CANTCREATEDC"; - break; - case DDERR_NODC: - szError = "DDERR_NODC"; + case DDERR_CLIPPERISUSINGHWND: + szError = "DDERR_CLIPPERISUSINGHWND"; break; - case DDERR_WRONGMODE: - szError = "DDERR_WRONGMODE"; + case DDERR_COLORKEYNOTSET: + szError = "DDERR_COLORKEYNOTSET"; break; - case DDERR_IMPLICITLYCREATED: - szError = "DDERR_IMPLICITLYCREATED"; + case DDERR_CURRENTLYNOTAVAIL: + szError = "DDERR_CURRENTLYNOTAVAIL"; break; - case DDERR_NOTPALETTIZED: - szError = "DDERR_NOTPALETTIZED"; + case DDERR_DIRECTDRAWALREADYCREATED: + szError = "DDERR_DIRECTDRAWALREADYCREATED"; break; - case DDERR_NOMIPMAPHW: - szError = "DDERR_NOMIPMAPHW"; + case DDERR_EXCEPTION: + szError = "DDERR_EXCEPTION"; break; - case DDERR_INVALIDSURFACETYPE: - szError = "DDERR_INVALIDSURFACETYPE"; + case DDERR_EXCLUSIVEMODEALREADYSET: + szError = "DDERR_EXCLUSIVEMODEALREADYSET"; break; - case DDERR_DCALREADYCREATED: - szError = "DDERR_DCALREADYCREATED"; + case DDERR_GENERIC: + szError = "DDERR_GENERIC"; break; - case DDERR_NOPALETTEHW: - szError = "DDERR_NOPALETTEHW"; + case DDERR_HEIGHTALIGN: + szError = "DDERR_HEIGHTALIGN"; break; - case DDERR_DIRECTDRAWALREADYCREATED: - szError = "DDERR_DIRECTDRAWALREADYCREATED"; + case DDERR_HWNDALREADYSET: + szError = "DDERR_HWNDALREADYSET"; break; - case DDERR_NODIRECTDRAWHW: - szError = "DDERR_NODIRECTDRAWHW"; + case DDERR_HWNDSUBCLASSED: + szError = "DDERR_HWNDSUBCLASSED"; break; - case DDERR_PRIMARYSURFACEALREADYEXISTS: - szError = "DDERR_PRIMARYSURFACEALREADYEXISTS"; + case DDERR_IMPLICITLYCREATED: + szError = "DDERR_IMPLICITLYCREATED"; break; - case DDERR_NOEMULATION: - szError = "DDERR_NOEMULATION"; + case DDERR_INCOMPATIBLEPRIMARY: + szError = "DDERR_INCOMPATIBLEPRIMARY"; break; - case DDERR_REGIONTOOSMALL: - szError = "DDERR_REGIONTOOSMALL"; + case DDERR_INVALIDCAPS: + szError = "DDERR_INVALIDCAPS"; break; - case DDERR_CLIPPERISUSINGHWND: - szError = "DDERR_CLIPPERISUSINGHWND"; + case DDERR_INVALIDCLIPLIST: + szError = "DDERR_INVALIDCLIPLIST"; break; - case DDERR_NOCLIPPERATTACHED: - szError = "DDERR_NOCLIPPERATTACHED"; + case DDERR_INVALIDDIRECTDRAWGUID: + szError = "DDERR_INVALIDDIRECTDRAWGUID"; break; - case DDERR_NOHWND: - szError = "DDERR_NOHWND"; + case DDERR_INVALIDMODE: + szError = "DDERR_INVALIDMODE"; break; - case DDERR_HWNDSUBCLASSED: - szError = "DDERR_HWNDSUBCLASSED"; + case DDERR_INVALIDOBJECT: + szError = "DDERR_INVALIDOBJECT"; break; - case DDERR_HWNDALREADYSET: - szError = "DDERR_HWNDALREADYSET"; + case DDERR_INVALIDPARAMS: + szError = "DDERR_INVALIDPARAMS"; break; - case DDERR_NOPALETTEATTACHED: - szError = "DDERR_NOPALETTEATTACHED"; + case DDERR_INVALIDPIXELFORMAT: + szError = "DDERR_INVALIDPIXELFORMAT"; break; - case DDERR_INVALIDDIRECTDRAWGUID: - szError = "DDERR_INVALIDDIRECTDRAWGUID"; + case DDERR_INVALIDPOSITION: + szError = "DDERR_INVALIDPOSITION"; break; - case DDERR_UNSUPPORTEDFORMAT: - szError = "DDERR_UNSUPPORTEDFORMAT"; + case DDERR_INVALIDRECT: + szError = "DDERR_INVALIDRECT"; break; - case DDERR_UNSUPPORTEDMASK: - szError = "DDERR_UNSUPPORTEDMASK"; + case DDERR_LOCKEDSURFACES: + szError = "DDERR_LOCKEDSURFACES"; break; - case DDERR_VERTICALBLANKINPROGRESS: - szError = "DDERR_VERTICALBLANKINPROGRESS"; + case DDERR_NO3D: + szError = "DDERR_NO3D"; break; - case DDERR_WASSTILLDRAWING: - szError = "DDERR_WASSTILLDRAWING"; + case DDERR_NOALPHAHW: + szError = "DDERR_NOALPHAHW"; break; - case DDERR_XALIGN: - szError = "DDERR_XALIGN"; + case DDERR_NOBLTHW: + szError = "DDERR_NOBLTHW"; break; - case DDERR_TOOBIGWIDTH: - szError = "DDERR_TOOBIGWIDTH"; + case DDERR_NOCLIPLIST: + szError = "DDERR_NOCLIPLIST"; break; - case DDERR_CANTLOCKSURFACE: - szError = "DDERR_CANTLOCKSURFACE"; + case DDERR_NOCLIPPERATTACHED: + szError = "DDERR_NOCLIPPERATTACHED"; break; - case DDERR_SURFACEISOBSCURED: - szError = "DDERR_SURFACEISOBSCURED"; + case DDERR_NOCOLORCONVHW: + szError = "DDERR_NOCOLORCONVHW"; break; - case DDERR_SURFACELOST: - szError = "DDERR_SURFACELOST"; + case DDERR_NOCOLORKEY: + szError = "DDERR_NOCOLORKEY"; break; - case DDERR_SURFACENOTATTACHED: - szError = "DDERR_SURFACENOTATTACHED"; + case DDERR_NOCOLORKEYHW: + szError = "DDERR_NOCOLORKEYHW"; break; - case DDERR_TOOBIGHEIGHT: - szError = "DDERR_TOOBIGHEIGHT"; + case DDERR_NOCOOPERATIVELEVELSET: + szError = "DDERR_NOCOOPERATIVELEVELSET"; break; - case DDERR_TOOBIGSIZE: - szError = "DDERR_TOOBIGSIZE"; + case DDERR_NODC: + szError = "DDERR_NODC"; break; - case DDERR_SURFACEBUSY: - szError = "DDERR_SURFACEBUSY"; + case DDERR_NODDROPSHW: + szError = "DDERR_NODDROPSHW"; break; - case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: - szError = "DDERR_OVERLAYCOLORKEYONLYONEACTIVE"; + case DDERR_NODIRECTDRAWHW: + szError = "DDERR_NODIRECTDRAWHW"; break; - case DDERR_PALETTEBUSY: - szError = "DDERR_PALETTEBUSY"; + case DDERR_NOEMULATION: + szError = "DDERR_NOEMULATION"; break; - case DDERR_COLORKEYNOTSET: - szError = "DDERR_COLORKEYNOTSET"; + case DDERR_NOEXCLUSIVEMODE: + szError = "DDERR_NOEXCLUSIVEMODE"; break; - case DDERR_SURFACEALREADYATTACHED: - szError = "DDERR_SURFACEALREADYATTACHED"; + case DDERR_NOFLIPHW: + szError = "DDERR_NOFLIPHW"; break; - case DDERR_SURFACEALREADYDEPENDENT: - szError = "DDERR_SURFACEALREADYDEPENDENT"; + case DDERR_NOGDI: + szError = "DDERR_NOGDI"; break; - case DDERR_OVERLAYCANTCLIP: - szError = "DDERR_OVERLAYCANTCLIP"; + case DDERR_NOHWND: + szError = "DDERR_NOHWND"; break; - case DDERR_NOVSYNCHW: - szError = "DDERR_NOVSYNCHW"; + case DDERR_NOMIRRORHW: + szError = "DDERR_NOMIRRORHW"; break; - case DDERR_NOZBUFFERHW: - szError = "DDERR_NOZBUFFERHW"; + case DDERR_NOOVERLAYDEST: + szError = "DDERR_NOOVERLAYDEST"; break; - case DDERR_NOZOVERLAYHW: - szError = "DDERR_NOZOVERLAYHW"; + case DDERR_NOOVERLAYHW: + szError = "DDERR_NOOVERLAYHW"; break; - case DDERR_OUTOFCAPS: - szError = "DDERR_OUTOFCAPS"; + case DDERR_NOPALETTEATTACHED: + szError = "DDERR_NOPALETTEATTACHED"; break; - case DDERR_OUTOFVIDEOMEMORY: - szError = "DDERR_OUTOFVIDEOMEMORY"; + case DDERR_NOPALETTEHW: + szError = "DDERR_NOPALETTEHW"; break; - case DDERR_NOTEXTUREHW: - szError = "DDERR_NOTEXTUREHW"; + case DDERR_NORASTEROPHW: + szError = "DDERR_NORASTEROPHW"; break; case DDERR_NOROTATIONHW: szError = "DDERR_NOROTATIONHW"; @@ -294,101 +267,128 @@ void TraceErrorDD(HRESULT hError, char *pszBuffer, DWORD dwMaxChars) case DDERR_NOT8BITCOLOR: szError = "DDERR_NOT8BITCOLOR"; break; - case DDERR_NORASTEROPHW: - szError = "DDERR_NORASTEROPHW"; - break; - case DDERR_NOEXCLUSIVEMODE: - szError = "DDERR_NOEXCLUSIVEMODE"; - break; - case DDERR_NOFLIPHW: - szError = "DDERR_NOFLIPHW"; + case DDERR_NOTAOVERLAYSURFACE: + szError = "DDERR_NOTAOVERLAYSURFACE"; break; - case DDERR_NOGDI: - szError = "DDERR_NOGDI"; + case DDERR_NOTEXTUREHW: + szError = "DDERR_NOTEXTUREHW"; break; - case DDERR_NOMIRRORHW: - szError = "DDERR_NOMIRRORHW"; + case DDERR_NOTFLIPPABLE: + szError = "DDERR_NOTFLIPPABLE"; break; case DDERR_NOTFOUND: szError = "DDERR_NOTFOUND"; break; - case DDERR_NOOVERLAYHW: - szError = "DDERR_NOOVERLAYHW"; + case DDERR_NOTLOCKED: + szError = "DDERR_NOTLOCKED"; break; - case DDERR_NOCOLORKEYHW: - szError = "DDERR_NOCOLORKEYHW"; + case DDERR_NOTPALETTIZED: + szError = "DDERR_NOTPALETTIZED"; break; - case DDERR_NOALPHAHW: - szError = "DDERR_NOALPHAHW"; + case DDERR_NOVSYNCHW: + szError = "DDERR_NOVSYNCHW"; break; - case DDERR_NOCLIPLIST: - szError = "DDERR_NOCLIPLIST"; + case DDERR_NOZBUFFERHW: + szError = "DDERR_NOZBUFFERHW"; break; - case DDERR_NOCOLORCONVHW: - szError = "DDERR_NOCOLORCONVHW"; + case DDERR_NOZOVERLAYHW: + szError = "DDERR_NOZOVERLAYHW"; break; - case DDERR_NOCOOPERATIVELEVELSET: - szError = "DDERR_NOCOOPERATIVELEVELSET"; + case DDERR_OUTOFCAPS: + szError = "DDERR_OUTOFCAPS"; break; - case DDERR_NOCOLORKEY: - szError = "DDERR_NOCOLORKEY"; + case DDERR_OUTOFMEMORY: + szError = "DDERR_OUTOFMEMORY"; break; - case DDERR_NO3D: - szError = "DDERR_NO3D"; + case DDERR_OUTOFVIDEOMEMORY: + szError = "DDERR_OUTOFVIDEOMEMORY"; break; - case DDERR_INVALIDMODE: - szError = "DDERR_INVALIDMODE"; + case DDERR_OVERLAYCANTCLIP: + szError = "DDERR_OVERLAYCANTCLIP"; break; - case DDERR_INVALIDOBJECT: - szError = "DDERR_INVALIDOBJECT"; + case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: + szError = "DDERR_OVERLAYCOLORKEYONLYONEACTIVE"; break; - case DDERR_INVALIDPIXELFORMAT: - szError = "DDERR_INVALIDPIXELFORMAT"; + case DDERR_OVERLAYNOTVISIBLE: + szError = "DDERR_OVERLAYNOTVISIBLE"; break; - case DDERR_INVALIDRECT: - szError = "DDERR_INVALIDRECT"; + case DDERR_PALETTEBUSY: + szError = "DDERR_PALETTEBUSY"; break; - case DDERR_LOCKEDSURFACES: - szError = "DDERR_LOCKEDSURFACES"; + case DDERR_PRIMARYSURFACEALREADYEXISTS: + szError = "DDERR_PRIMARYSURFACEALREADYEXISTS"; break; - case DDERR_INVALIDCLIPLIST: - szError = "DDERR_INVALIDCLIPLIST"; + case DDERR_REGIONTOOSMALL: + szError = "DDERR_REGIONTOOSMALL"; break; - case DDERR_CURRENTLYNOTAVAIL: - szError = "DDERR_CURRENTLYNOTAVAIL"; + case DDERR_SURFACEALREADYATTACHED: + szError = "DDERR_SURFACEALREADYATTACHED"; break; - case DDERR_EXCEPTION: - szError = "DDERR_EXCEPTION"; + case DDERR_SURFACEALREADYDEPENDENT: + szError = "DDERR_SURFACEALREADYDEPENDENT"; break; - case DDERR_HEIGHTALIGN: - szError = "DDERR_HEIGHTALIGN"; + case DDERR_SURFACEBUSY: + szError = "DDERR_SURFACEBUSY"; break; - case DDERR_INCOMPATIBLEPRIMARY: - szError = "DDERR_INCOMPATIBLEPRIMARY"; + case DDERR_SURFACEISOBSCURED: + szError = "DDERR_SURFACEISOBSCURED"; break; - case DDERR_INVALIDCAPS: - szError = "DDERR_INVALIDCAPS"; + case DDERR_SURFACELOST: + szError = "DDERR_SURFACELOST"; break; - case DDERR_CANNOTDETACHSURFACE: - szError = "DDERR_CANNOTDETACHSURFACE"; + case DDERR_SURFACENOTATTACHED: + szError = "DDERR_SURFACENOTATTACHED"; + break; + case DDERR_TOOBIGHEIGHT: + szError = "DDERR_TOOBIGHEIGHT"; + break; + case DDERR_TOOBIGSIZE: + szError = "DDERR_TOOBIGSIZE"; + break; + case DDERR_TOOBIGWIDTH: + szError = "DDERR_TOOBIGWIDTH"; break; case DDERR_UNSUPPORTED: szError = "DDERR_UNSUPPORTED"; break; - case DDERR_GENERIC: - szError = "DDERR_GENERIC"; + case DDERR_UNSUPPORTEDFORMAT: + szError = "DDERR_UNSUPPORTEDFORMAT"; break; - case DDERR_OUTOFMEMORY: - szError = "DDERR_OUTOFMEMORY"; + case DDERR_UNSUPPORTEDMASK: + szError = "DDERR_UNSUPPORTEDMASK"; break; - case DDERR_INVALIDPARAMS: - szError = "DDERR_INVALIDPARAMS"; + case DDERR_VERTICALBLANKINPROGRESS: + szError = "DDERR_VERTICALBLANKINPROGRESS"; break; - case DDERR_ALREADYINITIALIZED: - szError = "DDERR_ALREADYINITIALIZED"; + case DDERR_WASSTILLDRAWING: + szError = "DDERR_WASSTILLDRAWING"; break; - case DDERR_CANNOTATTACHSURFACE: - szError = "DDERR_CANNOTATTACHSURFACE"; + case DDERR_WRONGMODE: + szError = "DDERR_WRONGMODE"; + break; + case DDERR_XALIGN: + szError = "DDERR_XALIGN"; + break; + case DDERR_CANTLOCKSURFACE: + szError = "DDERR_CANTLOCKSURFACE"; + break; + case DDERR_CANTPAGELOCK: + szError = "DDERR_CANTPAGELOCK"; + break; + case DDERR_CANTPAGEUNLOCK: + szError = "DDERR_CANTPAGEUNLOCK"; + break; + case DDERR_DCALREADYCREATED: + szError = "DDERR_DCALREADYCREATED"; + break; + case DDERR_INVALIDSURFACETYPE: + szError = "DDERR_INVALIDSURFACETYPE"; + break; + case DDERR_NOMIPMAPHW: + szError = "DDERR_NOMIPMAPHW"; + break; + case DDERR_NOTPAGELOCKED: + szError = "DDERR_NOTPAGELOCKED"; break; default: { const char szUnknown[] = "DDERR unknown 0x%x"; From d008af43b05b101d60b31d08cd41e3bf9ef9d391 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 11 Apr 2020 14:33:44 +0200 Subject: [PATCH 05/19] Semantic code style cleanups --- Source/help.cpp | 2 +- Source/init.cpp | 18 +++++++-------- Source/inv.cpp | 24 ++++++++++---------- Source/items.cpp | 53 +++++++++++++++++++++------------------------ Source/lighting.cpp | 28 ++++++++++++------------ Source/loadsave.cpp | 4 ++-- Source/movie.cpp | 2 +- Source/scrollrt.cpp | 2 +- Source/setmaps.cpp | 16 +++++++------- Source/themes.cpp | 2 +- 10 files changed, 74 insertions(+), 77 deletions(-) diff --git a/Source/help.cpp b/Source/help.cpp index 60f5ca4ec..84dc9a2b2 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -458,7 +458,7 @@ void DrawHelp() PrintSString(0, 2, TRUE, "Diablo Help", COL_GOLD, 0); DrawSLine(5); - s = gszHelpText; + s = &gszHelpText[0]; for (i = 0; i < help_select_line; i++) { c = 0; diff --git a/Source/init.cpp b/Source/init.cpp index 338374fbb..610052766 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -27,7 +27,7 @@ char gszProductName[MAX_PATH] = "Diablo v1.09"; void init_cleanup(BOOL show_cursor) { pfile_flush_W(); - init_disable_screensaver(0); + init_disable_screensaver(FALSE); init_run_office_from_start_menu(); if (diabdat_mpq) { @@ -130,7 +130,7 @@ void init_disable_screensaver(BOOLEAN disable) if (disable) { cbData = 16; - success = RegQueryValueEx(phkResult, "ScreenSaveActive", 0, &Type, (LPBYTE)Data, &cbData); + success = RegQueryValueEx(phkResult, "ScreenSaveActive", NULL, &Type, (LPBYTE)Data, &cbData); if (success == ERROR_SUCCESS) screensaver_enabled_prev = Data[0] != '0'; enabled = FALSE; @@ -138,9 +138,9 @@ void init_disable_screensaver(BOOLEAN disable) enabled = screensaver_enabled_prev; } - Data[1] = 0; Data[0] = enabled ? '1' : '0'; - RegSetValueEx(phkResult, "ScreenSaveActive", 0, REG_SZ, (const BYTE *)Data, 2); + Data[1] = 0; + RegSetValueEx(phkResult, "ScreenSaveActive", NULL, REG_SZ, (const BYTE *)Data, 2); RegCloseKey(phkResult); } @@ -158,7 +158,7 @@ void init_create_window(int nCmdShow) wcex.lpfnWndProc = WindowProc; wcex.hInstance = ghInst; wcex.hIcon = LoadIcon(ghInst, MAKEINTRESOURCE(IDI_ICON1)); - wcex.hCursor = LoadCursor(0, IDC_ARROW); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = GAME_NAME; wcex.lpszClassName = "DIABLO"; @@ -183,7 +183,7 @@ void init_create_window(int nCmdShow) BlackPalette(); snd_init(hWnd); init_archives(); - init_disable_screensaver(1); + init_disable_screensaver(TRUE); } void init_kill_mom_parent() @@ -191,7 +191,7 @@ void init_kill_mom_parent() HWND handle; handle = init_find_mom_parent(); - if (handle) { + if (handle != NULL) { PostMessage(handle, WM_CLOSE, 0, 0); killed_mom_parent = TRUE; } @@ -223,7 +223,7 @@ void init_await_mom_parent_exit() } do { Sleep(250); - } while (GetTickCount() - tick <= 4000 && init_find_mom_parent()); + } while (GetTickCount() - tick <= 4000 && init_find_mom_parent() != NULL); } void init_archives() @@ -406,7 +406,7 @@ LRESULT __stdcall MainWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) break; case WM_DESTROY: init_cleanup(TRUE); - ghMainWnd = 0; + ghMainWnd = NULL; PostQuitMessage(0); break; case WM_PAINT: diff --git a/Source/inv.cpp b/Source/inv.cpp index 1304a07a7..1cb54a7c7 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -26,7 +26,7 @@ int sgdwLastTime; // check name * 65 66 67 68 69 70 71 72 * @see graphics/inv/inventory.png */ -const InvXY InvRect[73] = { +const InvXY InvRect[] = { // clang-format off // X, Y { RIGHT_PANEL + 132, 31 }, // helmet @@ -321,14 +321,14 @@ void DrawInv() if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iLoc == ILOC_TWOHAND) { InvDrawSlotBack(RIGHT_PANEL_X + 247, 160 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); light_table_index = 0; - cel_transparency_active = 1; + cel_transparency_active = TRUE; pBuff = frame_width == INV_SLOT_SIZE_PX ? &gpBuffer[SCREENXY(RIGHT_PANEL_X + 197, SCREEN_Y)] : &gpBuffer[SCREENXY(RIGHT_PANEL_X + 183, SCREEN_Y)]; CelClippedBlitLightTrans(pBuff, pCursCels, frame, frame_width, 0, 8); - cel_transparency_active = 0; + cel_transparency_active = FALSE; } } if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_NONE) { @@ -1233,7 +1233,7 @@ void CheckInvCut(int pnum, int mx, int my) if (r >= SLOTXY_INV_FIRST && r <= SLOTXY_INV_LAST) { ig = r - SLOTXY_INV_FIRST; ii = plr[pnum].InvGrid[ig]; - if (ii) { + if (ii != 0) { iv = ii; if (ii <= 0) { iv = -ii; @@ -1408,7 +1408,7 @@ void CheckBookLevel(int pnum) if (plr[pnum].HoldItem._iMiscId == IMISC_BOOK) { plr[pnum].HoldItem._iMinMag = spelldata[plr[pnum].HoldItem._iSpell].sMinInt; slvl = plr[pnum]._pSplLvl[plr[pnum].HoldItem._iSpell]; - while (slvl) { + while (slvl != 0) { plr[pnum].HoldItem._iMinMag += 20 * plr[pnum].HoldItem._iMinMag / 100; slvl--; if (plr[pnum].HoldItem._iMinMag + 20 * plr[pnum].HoldItem._iMinMag / 100 > 255) { @@ -1442,7 +1442,7 @@ void CheckQuestItem(int pnum) quests[Q_ANVIL]._qvar1 = 1; } #ifndef SPAWN - if (quests[Q_ANVIL]._qlog == 1) { + if (quests[Q_ANVIL]._qlog == TRUE) { sfxdelay = 10; if (plr[myplr]._pClass == PC_WARRIOR) { sfxdnum = PS_WARR89; @@ -1472,7 +1472,7 @@ void CheckQuestItem(int pnum) quests[Q_ROCK]._qvar1 = 1; } #ifndef SPAWN - if (quests[Q_ROCK]._qlog == 1) { + if (quests[Q_ROCK]._qlog == TRUE) { sfxdelay = 10; if (plr[myplr]._pClass == PC_WARRIOR) { sfxdnum = PS_WARR87; @@ -1508,7 +1508,7 @@ void InvGetItem(int pnum, int ii) dropGoldValue = 0; } - if (dItem[item[ii]._ix][item[ii]._iy]) { + if (dItem[item[ii]._ix][item[ii]._iy] != 0) { if (myplr == pnum && pcurs >= CURSOR_FIRSTITEM) NetSendCmdPItem(TRUE, CMD_SYNCPUTITEM, plr[myplr]._px, plr[myplr]._py); item[ii]._iCreateInfo &= ~0x8000; @@ -1731,7 +1731,7 @@ BOOL CanPut(int x, int y) if (nSolidTable[dPiece[x][y]]) return FALSE; - if (dObject[x][y]) { + if (dObject[x][y] != 0) { if (object[dObject[x][y] > 0 ? dObject[x][y] - 1 : -1 - dObject[x][y]]._oSolidFlag) return FALSE; } @@ -1994,7 +1994,7 @@ char CheckInvHLight() pi = &p->InvBody[rv]; } else if (r >= 25 && r <= 64) { r = abs(p->InvGrid[r - 25]); - if (!r) + if (r == 0) return -1; ii = r - 1; rv = ii + 7; @@ -2131,7 +2131,7 @@ BOOL UseInvItem(int pnum, int cii) return TRUE; if (pcurs != CURSOR_HAND) return TRUE; - if (stextflag) + if (stextflag != STORE_NONE) return TRUE; if (cii <= INVITEM_HAND_RIGHT) return FALSE; @@ -2236,7 +2236,7 @@ void DoTelekinesis() NetSendCmdParam1(TRUE, CMD_OPOBJT, pcursobj); if (pcursitem != -1) NetSendCmdGItem(TRUE, CMD_REQUESTAGITEM, myplr, myplr, pcursitem); - if (pcursmonst != -1 && !M_Talker(pcursmonst) && !monster[pcursmonst].mtalkmsg) + if (pcursmonst != -1 && !M_Talker(pcursmonst) && monster[pcursmonst].mtalkmsg == 0) NetSendCmdParam1(TRUE, CMD_KNOCKBACK, pcursmonst); SetCursor_(CURSOR_HAND); } diff --git a/Source/items.cpp b/Source/items.cpp index 557802247..fc4b0eba2 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -203,13 +203,13 @@ void InitItemGFX() BOOL ItemPlace(int xp, int yp) { - if (dMonster[xp][yp]) + if (dMonster[xp][yp] != 0) return FALSE; - if (dPlayer[xp][yp]) + if (dPlayer[xp][yp] != 0) return FALSE; - if (dItem[xp][yp]) + if (dItem[xp][yp] != 0) return FALSE; - if (dObject[xp][yp]) + if (dObject[xp][yp] != 0) return FALSE; if (dFlags[xp][yp] & BFLAG_POPULATED) return FALSE; @@ -469,19 +469,16 @@ void CalcPlrItemVals(int p, BOOL Loadgfx) lr = 0; } - if (mr > 75) { - mr = 75; - } + if (mr > MAXRESIST) + mr = MAXRESIST; plr[p]._pMagResist = mr; - if (fr > 75) { - fr = 75; - } + if (fr > MAXRESIST) + fr = MAXRESIST; plr[p]._pFireResist = fr; - if (lr > 75) { - lr = 75; - } + if (lr > MAXRESIST) + lr = MAXRESIST; plr[p]._pLghtResist = lr; if (plr[p]._pClass == PC_WARRIOR) { @@ -734,7 +731,7 @@ void CalcPlrBookVals(int p) { int i, slvl; - if (!currlevel) { + if (currlevel == 0) { for (i = 1; witchitem[i]._itype != ITYPE_NONE; i++) { WitchBookLevel(i); witchitem[i]._iStatFlag = StoreStatOk(&witchitem[i]); @@ -746,7 +743,7 @@ void CalcPlrBookVals(int p) plr[p].InvList[i]._iMinMag = spelldata[plr[p].InvList[i]._iSpell].sMinInt; slvl = plr[p]._pSplLvl[plr[p].InvList[i]._iSpell]; - while (slvl) { + while (slvl != 0) { plr[p].InvList[i]._iMinMag += 20 * plr[p].InvList[i]._iMinMag / 100; slvl--; if (plr[p].InvList[i]._iMinMag + 20 * plr[p].InvList[i]._iMinMag / 100 > 255) { @@ -769,7 +766,7 @@ void CalcPlrInv(int p, BOOL Loadgfx) CalcPlrBookVals(p); CalcPlrScrolls(p); CalcPlrStaff(p); - if (p == myplr && !currlevel) + if (p == myplr && currlevel == 0) RecalcStoreStats(); } } @@ -879,7 +876,7 @@ void CreatePlrItems(int p) plr[p]._pNumInv = 0; - pi = plr[p].SpdList; + pi = &plr[p].SpdList[0]; for (i = MAXBELTITEMS; i != 0; i--) { pi->_itype = ITYPE_NONE; pi++; @@ -967,16 +964,16 @@ BOOL ItemSpaceOk(int i, int j) if (i < 0 || i >= MAXDUNX || j < 0 || j >= MAXDUNY) return FALSE; - if (dMonster[i][j]) + if (dMonster[i][j] != 0) return FALSE; - if (dPlayer[i][j]) + if (dPlayer[i][j] != 0) return FALSE; - if (dItem[i][j]) + if (dItem[i][j] != 0) return FALSE; - if (dObject[i][j]) { + if (dObject[i][j] != 0) { oi = dObject[i][j] > 0 ? dObject[i][j] - 1 : -(dObject[i][j] + 1); if (object[oi]._oSolidFlag) return FALSE; @@ -1121,7 +1118,7 @@ void GetBookSpell(int i, int lvl) if (lvl > 5) lvl = 5; #endif - s = 1; + s = SPL_FIREBOLT; while (rv > 0) { if (spelldata[s].sBookLvl != -1 && lvl >= spelldata[s].sBookLvl) { rv--; @@ -1226,7 +1223,7 @@ void GetStaffSpell(int i, int lvl, BOOL onlygood) if (lvl > 10) lvl = 10; #endif - s = 1; + s = SPL_FIREBOLT; while (rv > 0) { if (spelldata[s].sStaffLvl != -1 && l >= spelldata[s].sStaffLvl) { rv--; @@ -1238,7 +1235,7 @@ void GetStaffSpell(int i, int lvl, BOOL onlygood) if (gbMaxPlayers == 1 && s == SPL_HEALOTHER) s = SPL_FLARE; if (s == MAX_SPELLS) - s = 1; + s = SPL_FIREBOLT; } sprintf(istr, "%s of %s", item[i]._iName, spelldata[bs].sNameText); if (!control_WriteStringToBuffer((BYTE *)istr)) @@ -1683,7 +1680,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) goe = 0; if (!onlygood && random_(0, 3)) onlygood = TRUE; - if (!pre) { + if (pre == 0) { nt = 0; for (j = 0; PL_Prefix[j].PLPower != -1; j++) { if (flgs & PL_Prefix[j].PLIType) { @@ -1697,7 +1694,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) } } } - if (nt) { + if (nl != 0) { preidx = l[random_(23, nt)]; sprintf(istr, "%s %s", PL_Prefix[preidx].PLName, item[i]._iIName); strcpy(item[i]._iIName, istr); @@ -1725,7 +1722,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) nl++; } } - if (nl) { + if (nl != 0) { sufidx = l[random_(23, nl)]; sprintf(istr, "%s of %s", item[i]._iIName, PL_Suffix[sufidx].PLName); strcpy(item[i]._iIName, istr); @@ -1960,7 +1957,7 @@ int CheckUnique(int i, int lvl, int uper, BOOL recreate) } } - if (!numu) + if (numu == 0) return -1; random_(29, 10); /// BUGFIX: unused, last unique in array always gets chosen diff --git a/Source/lighting.cpp b/Source/lighting.cpp index 3895944d1..eb368fba5 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -994,7 +994,7 @@ void ToggleLighting() lightflag ^= TRUE; - if (lightflag) { + if (lightflag != 0) { memset(dLight, 0, sizeof(dLight)); } else { memcpy(dLight, dPreLight, sizeof(dLight)); @@ -1033,7 +1033,7 @@ int AddLight(int x, int y, int r) { int lid; - if (lightflag) { + if (lightflag != 0) { return -1; } @@ -1046,8 +1046,8 @@ int AddLight(int x, int y, int r) LightList[lid]._lradius = r; LightList[lid]._xoff = 0; LightList[lid]._yoff = 0; - LightList[lid]._ldel = 0; - LightList[lid]._lunflag = 0; + LightList[lid]._ldel = FALSE; + LightList[lid]._lunflag = FALSE; dolighting = TRUE; } @@ -1060,7 +1060,7 @@ void AddUnLight(int i) return; } - LightList[i]._ldel = 1; + LightList[i]._ldel = TRUE; dolighting = TRUE; } @@ -1070,7 +1070,7 @@ void ChangeLightRadius(int i, int r) return; } - LightList[i]._lunflag = 1; + LightList[i]._lunflag = TRUE; LightList[i]._lunx = LightList[i]._lx; LightList[i]._luny = LightList[i]._ly; LightList[i]._lunr = LightList[i]._lradius; @@ -1084,7 +1084,7 @@ void ChangeLightXY(int i, int x, int y) return; } - LightList[i]._lunflag = 1; + LightList[i]._lunflag = TRUE; LightList[i]._lunx = LightList[i]._lx; LightList[i]._luny = LightList[i]._ly; LightList[i]._lunr = LightList[i]._lradius; @@ -1099,7 +1099,7 @@ void ChangeLightOff(int i, int x, int y) return; } - LightList[i]._lunflag = 1; + LightList[i]._lunflag = TRUE; LightList[i]._lunx = LightList[i]._lx; LightList[i]._luny = LightList[i]._ly; LightList[i]._lunr = LightList[i]._lradius; @@ -1114,7 +1114,7 @@ void ChangeLight(int i, int x, int y, int r) return; } - LightList[i]._lunflag = 1; + LightList[i]._lunflag = TRUE; LightList[i]._lunx = LightList[i]._lx; LightList[i]._luny = LightList[i]._ly; LightList[i]._lunr = LightList[i]._lradius; @@ -1129,7 +1129,7 @@ void ProcessLightList() int i, j; BYTE temp; - if (lightflag) { + if (lightflag != 0) { return; } @@ -1141,7 +1141,7 @@ void ProcessLightList() } if (LightList[j]._lunflag) { DoUnLight(LightList[j]._lunx, LightList[j]._luny, LightList[j]._lunr); - LightList[j]._lunflag = 0; + LightList[j]._lunflag = FALSE; } } for (i = 0; i < numlights; i++) { @@ -1210,7 +1210,7 @@ void ChangeVisionRadius(int id, int r) for (i = 0; i < numvision; i++) { if (VisionList[i]._lid == id) { - VisionList[i]._lunflag = 1; + VisionList[i]._lunflag = TRUE; VisionList[i]._lunx = VisionList[i]._lx; VisionList[i]._luny = VisionList[i]._ly; VisionList[i]._lunr = VisionList[i]._lradius; @@ -1226,7 +1226,7 @@ void ChangeVisionXY(int id, int x, int y) for (i = 0; i < numvision; i++) { if (VisionList[i]._lid == id) { - VisionList[i]._lunflag = 1; + VisionList[i]._lunflag = TRUE; VisionList[i]._lunx = VisionList[i]._lx; VisionList[i]._luny = VisionList[i]._ly; VisionList[i]._lunr = VisionList[i]._lradius; @@ -1249,7 +1249,7 @@ void ProcessVisionList() } if (VisionList[i]._lunflag) { DoUnVision(VisionList[i]._lunx, VisionList[i]._luny, VisionList[i]._lunr); - VisionList[i]._lunflag = 0; + VisionList[i]._lunflag = FALSE; } } for (i = 0; i < TransVal; i++) { diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index a3dde56ca..352a6dc38 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -521,7 +521,7 @@ void SaveLevel() int dwLen; BYTE *SaveBuff; - if (!currlevel) + if (currlevel == 0) glSeedTbl[0] = GetRndSeed(); dwLen = codec_get_encoded_len(FILEBUFF); @@ -694,7 +694,7 @@ void LoadLevel() for (i = 0; i < MAX_PLRS; i++) { if (plr[i].plractive && currlevel == plr[i].plrlevel) - LightList[plr[i]._plid]._lunflag = 1; + LightList[plr[i]._plid]._lunflag = TRUE; } mem_free_dbg(LoadBuff); diff --git a/Source/movie.cpp b/Source/movie.cpp index 1e3f81293..4b1ec3484 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -21,7 +21,7 @@ void play_movie(char *pszMovie, BOOL user_can_close) } saveProc = SetWindowProc(MovieWndProc); - InvalidateRect(ghMainWnd, 0, 0); + InvalidateRect(ghMainWnd, NULL, 0); UpdateWindow(ghMainWnd); movie_playing = TRUE; sound_disable_music(TRUE); diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 298031cf0..63640afee 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -2843,7 +2843,7 @@ void scrollrt_draw_game_screen(BOOL draw_cursor) unlock_buf(0); } - DrawMain(hgt, 0, 0, 0, 0, 0); + DrawMain(hgt, FALSE, FALSE, FALSE, FALSE, FALSE); if (draw_cursor) { lock_buf(0); diff --git a/Source/setmaps.cpp b/Source/setmaps.cpp index 286d6cd0a..53666bd74 100644 --- a/Source/setmaps.cpp +++ b/Source/setmaps.cpp @@ -61,7 +61,7 @@ char *quest_level_names[] = { "Bone Chamber", "Maze", "Poisoned Water Supply", - "Archbishop Lazarus' Lair" + "Archbishop Lazarus' Lair", }; int ObjIndex(int x, int y) @@ -140,10 +140,10 @@ void LoadSetMap() LoadPreL1Dungeon("Levels\\L1Data\\SklKng1.DUN", 83, 45); LoadL1Dungeon("Levels\\L1Data\\SklKng2.DUN", 83, 45); LoadPalette("Levels\\L1Data\\L1_2.pal"); - DRLG_AreaTrans(sizeof(SkelKingTrans1) / 4, SkelKingTrans1); - DRLG_ListTrans(sizeof(SkelKingTrans2) / 4, SkelKingTrans2); - DRLG_AreaTrans(sizeof(SkelKingTrans3) / 4, SkelKingTrans3); - DRLG_ListTrans(sizeof(SkelKingTrans4) / 4, SkelKingTrans4); + DRLG_AreaTrans(sizeof(SkelKingTrans1) / 4, &SkelKingTrans1[0]); + DRLG_ListTrans(sizeof(SkelKingTrans2) / 4, &SkelKingTrans2[0]); + DRLG_AreaTrans(sizeof(SkelKingTrans3) / 4, &SkelKingTrans3[0]); + DRLG_ListTrans(sizeof(SkelKingTrans4) / 4, &SkelKingTrans4[0]); AddL1Objs(0, 0, MAXDUNX, MAXDUNY); AddSKingObjs(); InitSKingTriggers(); @@ -152,9 +152,9 @@ void LoadSetMap() LoadPreL2Dungeon("Levels\\L2Data\\Bonecha2.DUN", 69, 39); LoadL2Dungeon("Levels\\L2Data\\Bonecha1.DUN", 69, 39); LoadPalette("Levels\\L2Data\\L2_2.pal"); - DRLG_ListTrans(sizeof(SkelChamTrans1) / 4, SkelChamTrans1); - DRLG_AreaTrans(sizeof(SkelChamTrans2) / 4, SkelChamTrans2); - DRLG_ListTrans(sizeof(SkelChamTrans3) / 4, SkelChamTrans3); + DRLG_ListTrans(sizeof(SkelChamTrans1) / 4, &SkelChamTrans1[0]); + DRLG_AreaTrans(sizeof(SkelChamTrans2) / 4, &SkelChamTrans2[0]); + DRLG_ListTrans(sizeof(SkelChamTrans3) / 4, &SkelChamTrans3[0]); AddL2Objs(0, 0, MAXDUNX, MAXDUNY); AddSChamObjs(); InitSChambTriggers(); diff --git a/Source/themes.cpp b/Source/themes.cpp index 541e63550..604666d6e 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -988,7 +988,7 @@ void UpdateL4Trans() for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { - if (dTransVal[i][j]) { + if (dTransVal[i][j] != 0) { dTransVal[i][j] = 1; } } From 350646fe9520b9112685a305712453cc27574459 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 11 Apr 2020 14:46:39 +0200 Subject: [PATCH 06/19] Correct signatures --- Source/init.cpp | 3 +-- Source/init.h | 2 +- Source/interfac.cpp | 4 ++-- Source/inv.cpp | 6 +++--- Source/setmaps.cpp | 14 +++++++------- Source/wave.cpp | 7 +++---- Source/wave.h | 4 ++-- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Source/init.cpp b/Source/init.cpp index 610052766..473c1b7df 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -319,7 +319,7 @@ HANDLE init_test_access(char *mpq_path, char *mpq_name, char *reg_loc, int dwPri return NULL; } -char *init_strip_trailing_slash(char *path) +void init_strip_trailing_slash(char *path) { char *result; @@ -328,7 +328,6 @@ char *init_strip_trailing_slash(char *path) if (!result[1]) *result = 0; } - return result; } BOOL init_read_test_file(char *pszPath, char *pszArchive, int dwPriority, HANDLE *phArchive) diff --git a/Source/init.h b/Source/init.h index 6867b23b4..6f66a452c 100644 --- a/Source/init.h +++ b/Source/init.h @@ -28,7 +28,7 @@ HWND init_find_mom_parent(); void init_await_mom_parent_exit(); void init_archives(); HANDLE init_test_access(char *mpq_path, char *mpq_name, char *reg_loc, int flags, int fs); -char *init_strip_trailing_slash(char *path); +void init_strip_trailing_slash(char *path); BOOL init_read_test_file(char *pszPath, char *pszArchive, int flags, HANDLE *phArchive); void init_get_file_info(); LRESULT __stdcall MainWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); diff --git a/Source/interfac.cpp b/Source/interfac.cpp index b4232a765..1cd6a3351 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -6,7 +6,7 @@ #include "all.h" #include "../3rdParty/Storm/Source/storm.h" -void *sgpBackCel; +BYTE *sgpBackCel; int sgdwProgress; int progress_id; @@ -43,7 +43,7 @@ void DrawCutscene() DWORD i; lock_buf(1); - CelDraw(PANEL_X, 480 + SCREEN_Y - 1, (BYTE *)sgpBackCel, 1, 640); + CelDraw(PANEL_X, 480 + SCREEN_Y - 1, sgpBackCel, 1, 640); for (i = 0; i < sgdwProgress; i++) { DrawProgress( diff --git a/Source/inv.cpp b/Source/inv.cpp index 1cb54a7c7..50b76d3fd 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1860,7 +1860,7 @@ int InvPutItem(int pnum, int x, int y) item[ii]._iy = y; RespawnItem(ii, TRUE); numitems++; - SetCursor_(CURSOR_HAND); + NewCursor(CURSOR_HAND); return ii; } @@ -2238,7 +2238,7 @@ void DoTelekinesis() NetSendCmdGItem(TRUE, CMD_REQUESTAGITEM, myplr, myplr, pcursitem); if (pcursmonst != -1 && !M_Talker(pcursmonst) && monster[pcursmonst].mtalkmsg == 0) NetSendCmdParam1(TRUE, CMD_KNOCKBACK, pcursmonst); - SetCursor_(CURSOR_HAND); + NewCursor(CURSOR_HAND); } int CalculateGold(int pnum) @@ -2264,7 +2264,7 @@ BOOL DropItemBeforeTrig() { if (TryInvPut()) { NetSendCmdPItem(TRUE, CMD_PUTITEM, cursmx, cursmy); - SetCursor_(CURSOR_HAND); + NewCursor(CURSOR_HAND); return TRUE; } diff --git a/Source/setmaps.cpp b/Source/setmaps.cpp index 53666bd74..2c6baf629 100644 --- a/Source/setmaps.cpp +++ b/Source/setmaps.cpp @@ -1,17 +1,17 @@ #include "all.h" // BUGFIX: constant data should be const -BYTE SkelKingTrans1[8] = { +BYTE SkelKingTrans1[] = { 19, 47, 26, 55, 26, 49, 30, 53 }; -BYTE SkelKingTrans2[8] = { +BYTE SkelKingTrans2[] = { 33, 19, 47, 29, 37, 29, 43, 39 }; -BYTE SkelKingTrans3[20] = { +BYTE SkelKingTrans3[] = { 27, 53, 35, 61, 27, 35, 34, 42, 45, 35, 53, 43, @@ -19,7 +19,7 @@ BYTE SkelKingTrans3[20] = { 31, 39, 49, 57 }; -BYTE SkelKingTrans4[28] = { +BYTE SkelKingTrans4[] = { 49, 45, 58, 51, 57, 31, 62, 37, 63, 31, 69, 40, @@ -29,7 +29,7 @@ BYTE SkelKingTrans4[28] = { 79, 43, 89, 53 }; -BYTE SkelChamTrans1[20] = { +BYTE SkelChamTrans1[] = { 43, 19, 50, 26, 51, 19, 59, 26, 35, 27, 42, 34, @@ -37,12 +37,12 @@ BYTE SkelChamTrans1[20] = { 50, 27, 59, 34 }; -BYTE SkelChamTrans2[8] = { +BYTE SkelChamTrans2[] = { 19, 31, 34, 47, 34, 35, 42, 42 }; -BYTE SkelChamTrans3[36] = { +BYTE SkelChamTrans3[] = { 43, 35, 50, 42, 51, 35, 62, 42, 63, 31, 66, 46, diff --git a/Source/wave.cpp b/Source/wave.cpp index fa8bd7999..e0fc8128e 100644 --- a/Source/wave.cpp +++ b/Source/wave.cpp @@ -1,9 +1,9 @@ #include "all.h" #include "../3rdParty/Storm/Source/storm.h" -BOOL WCloseFile(HANDLE file) +void WCloseFile(HANDLE file) { - return SFileCloseFile(file); + SFileCloseFile(file); } LONG WGetFileSize(HANDLE hsFile, DWORD *lpFileSizeHigh) @@ -82,7 +82,7 @@ BOOL LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx) return ret; } -void *AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos) +void AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos) { DWORD length; @@ -97,7 +97,6 @@ void *AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos) pMemFile->buf_len = length; pMemFile->buf = DiabloAllocPtr(length); pMemFile->file = hsFile; - return pMemFile->buf; } void FreeMemFile(MEMFILE *pMemFile) diff --git a/Source/wave.h b/Source/wave.h index 4f662fba1..7a608f688 100644 --- a/Source/wave.h +++ b/Source/wave.h @@ -2,14 +2,14 @@ #ifndef __WAVE_H__ #define __WAVE_H__ -BOOL WCloseFile(HANDLE file); +void WCloseFile(HANDLE file); LONG WGetFileSize(HANDLE hsFile, DWORD *lpFileSizeHigh); void WGetFileArchive(HANDLE hsFile, DWORD *retry, const char *FileName); BOOL WOpenFile(const char *FileName, HANDLE *phsFile, BOOL mayNotExist); void WReadFile(HANDLE hsFile, LPVOID buf, DWORD to_read); int WSetFilePointer(HANDLE file1, int offset, HANDLE file2, int whence); BOOL LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx); -void *AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos); +void AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos); void FreeMemFile(MEMFILE *pMemFile); BOOL ReadWaveFile(MEMFILE *pMemFile, WAVEFORMATEX *pwfx, CKINFO *chunk); BOOL ReadMemFile(MEMFILE *pMemFile, void *lpBuf, size_t length); From e7567859eeb5f1c7791bae49eb95c48bfec358f8 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 11 Apr 2020 14:48:01 +0200 Subject: [PATCH 07/19] Remove C fallback code --- Source/scrollrt.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 63640afee..e46e50826 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -2615,11 +2615,7 @@ static void DoBlitScreen(DWORD dwX, DWORD dwY, DWORD dwWdt, DWORD dwHgt) /// ASSERT: assert(! gpBuffer); dwTicks = GetTickCount(); while (1) { -#ifdef __cplusplus hDDVal = lpDDSPrimary->BltFast(dwX, dwY, lpDDSBackBuf, &SrcRect, DDBLTFAST_WAIT); -#else - hDDVal = lpDDSPrimary->lpVtbl->BltFast(lpDDSPrimary, dwX, dwY, lpDDSBackBuf, &SrcRect, DDBLTFAST_WAIT); -#endif if (hDDVal == DD_OK) { break; } @@ -2716,17 +2712,10 @@ static void DrawMain(int dwHgt, BOOL draw_desc, BOOL draw_hp, BOOL draw_mana, BO return; } -#ifdef __cplusplus if (lpDDSPrimary->IsLost() == DDERR_SURFACELOST) { if (lpDDSPrimary->Restore() != DD_OK) { return; } -#else - if (lpDDSPrimary->lpVtbl->IsLost(lpDDSPrimary) == DDERR_SURFACELOST) { - if (lpDDSPrimary->lpVtbl->Restore(lpDDSPrimary) != DD_OK) { - return; - } -#endif ResetPal(); ysize = SCREEN_HEIGHT; } @@ -2736,11 +2725,7 @@ static void DrawMain(int dwHgt, BOOL draw_desc, BOOL draw_hp, BOOL draw_mana, BO dwTicks = GetTickCount(); while (1) { DDS_desc.dwSize = sizeof(DDS_desc); -#ifdef __cplusplus hDDVal = lpDDSPrimary->Lock(NULL, &DDS_desc, DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL); -#else - hDDVal = lpDDSPrimary->lpVtbl->Lock(lpDDSPrimary, NULL, &DDS_desc, DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL); -#endif if (hDDVal == DD_OK) { break; } @@ -2807,11 +2792,7 @@ static void DrawMain(int dwHgt, BOOL draw_desc, BOOL draw_hp, BOOL draw_mana, BO } if (lpDDSBackBuf == NULL) { -#ifdef __cplusplus hDDVal = lpDDSPrimary->Unlock(NULL); -#else - hDDVal = lpDDSPrimary->lpVtbl->Unlock(lpDDSPrimary, NULL); -#endif if (hDDVal != DDERR_SURFACELOST && hDDVal != DD_OK) { DDErrMsg(hDDVal, 3779, "C:\\Src\\Diablo\\Source\\SCROLLRT.CPP"); } From 3b8bcf98bf9a959717f9a60baa5d5710337de925 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 11 Apr 2020 14:49:02 +0200 Subject: [PATCH 08/19] Enable assertions --- Source/engine.cpp | 140 ++++++++++++++++++++++---------------------- Source/interfac.cpp | 18 +++--- Source/inv.cpp | 14 ++--- Source/items.cpp | 4 +- Source/lighting.cpp | 2 +- Source/missiles.cpp | 4 +- Source/scrollrt.cpp | 8 +-- Source/sync.cpp | 6 +- Source/town.cpp | 12 ++-- 9 files changed, 102 insertions(+), 106 deletions(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index 6fe623b17..14d367569 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -82,10 +82,10 @@ void CelBlit(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; - /// ASSERT: assert(pDecodeTo != NULL); + assert(pDecodeTo != NULL); if (pDecodeTo == NULL) return; - /// ASSERT: assert(pRLEBytes != NULL); + assert(pRLEBytes != NULL); if (pRLEBytes == NULL) return; @@ -190,10 +190,10 @@ void CelDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) int nDataSize; BYTE *pRLEBytes; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -213,10 +213,10 @@ void CelBlitFrame(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth) int nDataSize; BYTE *pRLEBytes; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; - /// ASSERT: assert(pBuff != NULL); + assert(pBuff != NULL); if (pBuff == NULL) return; @@ -240,10 +240,10 @@ void CelClippedDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Ce DWORD *pFrameTable; int nDataStart, nDataSize, nDataCap; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -286,10 +286,10 @@ void CelClippedBlit(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSk DWORD *pFrameTable; int nDataStart, nDataSize, nDataCap; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; - /// ASSERT: assert(pBuff != NULL); + assert(pBuff != NULL); if (pBuff == NULL) return; @@ -325,10 +325,10 @@ void CelBlitLight(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) int w; BYTE *tbl; - /// ASSERT: assert(pDecodeTo != NULL); + assert(pDecodeTo != NULL); if (pDecodeTo == NULL) return; - /// ASSERT: assert(pRLEBytes != NULL); + assert(pRLEBytes != NULL); if (pRLEBytes == NULL) return; @@ -486,10 +486,10 @@ void CelBlitLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWid BOOL shift; BYTE *tbl; - /// ASSERT: assert(pDecodeTo != NULL); + assert(pDecodeTo != NULL); if (pDecodeTo == NULL) return; - /// ASSERT: assert(pRLEBytes != NULL); + assert(pRLEBytes != NULL); if (pRLEBytes == NULL) return; @@ -680,10 +680,10 @@ void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) int nDataSize; BYTE *pDecodeTo, *pRLEBytes; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -712,10 +712,10 @@ void CelClippedDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, i BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -760,10 +760,10 @@ void CelClippedBlitLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, BYTE *pRLEBytes; DWORD *pFrameTable; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; - /// ASSERT: assert(pBuff != NULL); + assert(pBuff != NULL); if (pBuff == NULL) return; @@ -811,10 +811,10 @@ void CelDrawLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int C BYTE *pRLEBytes, *dst, *tbl; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -929,13 +929,13 @@ void CelBlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; - /// ASSERT: assert(pDecodeTo != NULL); + assert(pDecodeTo != NULL); if (pDecodeTo == NULL) return; - /// ASSERT: assert(pRLEBytes != NULL); + assert(pRLEBytes != NULL); if (pRLEBytes == NULL) return; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; @@ -1054,10 +1054,10 @@ void CelClippedDrawSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, in DWORD *pFrameTable; int nDataStart, nDataSize, nDataCap; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -1100,10 +1100,10 @@ void CelClippedBlitSafe(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int C DWORD *pFrameTable; int nDataStart, nDataSize, nDataCap; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; - /// ASSERT: assert(pBuff != NULL); + assert(pBuff != NULL); if (pBuff == NULL) return; @@ -1139,13 +1139,13 @@ void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidt int w; BYTE *tbl; - /// ASSERT: assert(pDecodeTo != NULL); + assert(pDecodeTo != NULL); if (pDecodeTo == NULL) return; - /// ASSERT: assert(pRLEBytes != NULL); + assert(pRLEBytes != NULL); if (pRLEBytes == NULL) return; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; @@ -1315,13 +1315,13 @@ void CelBlitLightTransSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int BOOL shift; BYTE *tbl; - /// ASSERT: assert(pDecodeTo != NULL); + assert(pDecodeTo != NULL); if (pDecodeTo == NULL) return; - /// ASSERT: assert(pRLEBytes != NULL); + assert(pRLEBytes != NULL); if (pRLEBytes == NULL) return; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; @@ -1526,10 +1526,10 @@ void CelDrawLightSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -1574,7 +1574,7 @@ void CelClippedBlitLightTransSafe(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWi BYTE *pRLEBytes; DWORD *pFrameTable; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -1622,10 +1622,10 @@ void CelDrawLightRedSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, i BYTE *pRLEBytes, *dst, *tbl; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; @@ -1751,10 +1751,10 @@ void CelBlitWidth(BYTE *pBuff, int x, int y, int wdt, BYTE *pCelBuff, int nCel, { BYTE *pRLEBytes, *dst, *end; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; - /// ASSERT: assert(pBuff != NULL); + assert(pBuff != NULL); if (pBuff == NULL) return; @@ -1877,10 +1877,10 @@ void CelBlitOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWid int nDataStart, nDataSize, nDataCap, w; BYTE *pRLEBytes, *dst; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; @@ -2025,10 +2025,10 @@ void CelBlitOutlineSafe(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int int nDataStart, nDataSize, nDataCap, w; BYTE *pRLEBytes, *dst; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gpBuffer == NULL) return; @@ -2209,7 +2209,7 @@ void ENG_set_pixel(int sx, int sy, BYTE col) { BYTE *dst; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (sy < 0 || sy >= SCREEN_HEIGHT + SCREEN_Y || sx < SCREEN_X || sx >= SCREEN_WIDTH + SCREEN_X) return; @@ -2240,7 +2240,7 @@ void engine_draw_pixel(int sx, int sy) { BYTE *dst; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); if (gbRotateMap) { if (gbNotInView && (sx < 0 || sx >= SCREEN_HEIGHT + SCREEN_Y || sy < SCREEN_X || sy >= SCREEN_WIDTH + SCREEN_X)) @@ -2661,7 +2661,7 @@ DWORD LoadFileWithMem(const char *pszName, BYTE *p) DWORD dwFileLen; HANDLE hsFile; - /// ASSERT: assert(pszName); + assert(pszName); if (p == NULL) { app_fatal("LoadFileWithMem(NULL):\n%s", pszName); } @@ -2692,8 +2692,8 @@ void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel) BYTE *dst; DWORD *pFrameTable; - /// ASSERT: assert(p != NULL); - /// ASSERT: assert(ttbl != NULL); + assert(p != NULL); + assert(ttbl != NULL); for (i = 1; i <= nCel; i++) { pFrameTable = (DWORD *)&p[4 * i]; @@ -2702,17 +2702,17 @@ void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel) while (nDataSize) { width = *dst++; nDataSize--; - /// ASSERT: assert(nDataSize >= 0); + assert(nDataSize >= 0); if (width < 0) { width = -width; if (width > 65) { nDataSize--; - /// ASSERT: assert(nDataSize >= 0); + assert(nDataSize >= 0); *dst = ttbl[*dst]; dst++; } else { nDataSize -= width; - /// ASSERT: assert(nDataSize >= 0); + assert(nDataSize >= 0); while (width) { *dst = ttbl[*dst]; dst++; @@ -2740,10 +2740,10 @@ void Cl2Draw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, DWORD *pFrameTable; int nDataStart, nDataSize; - /// ASSERT: assert(gpBuffer != NULL); + assert(gpBuffer != NULL); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; assert(nCel > 0); @@ -2936,10 +2936,10 @@ void Cl2DrawOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWid BYTE *pRLEBytes; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer != NULL); + assert(gpBuffer != NULL); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; assert(nCel > 0); @@ -3155,10 +3155,10 @@ void Cl2DrawLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int C BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer != NULL); + assert(gpBuffer != NULL); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; assert(nCel > 0); @@ -3371,10 +3371,10 @@ void Cl2DrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelS BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer != NULL); + assert(gpBuffer != NULL); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; assert(nCel > 0); @@ -3421,10 +3421,10 @@ void Cl2DrawSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSk DWORD *pFrameTable; int nDataStart, nDataSize; - /// ASSERT: assert(gpBuffer != NULL); + assert(gpBuffer != NULL); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; assert(nCel > 0); @@ -3630,10 +3630,10 @@ void Cl2DrawOutlineSafe(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int BYTE *pRLEBytes; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer != NULL); + assert(gpBuffer != NULL); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; assert(nCel > 0); @@ -3862,10 +3862,10 @@ void Cl2DrawLightTblSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, i BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer != NULL); + assert(gpBuffer != NULL); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; assert(nCel > 0); @@ -4091,10 +4091,10 @@ void Cl2DrawLightSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; - /// ASSERT: assert(gpBuffer != NULL); + assert(gpBuffer != NULL); if (gpBuffer == NULL) return; - /// ASSERT: assert(pCelBuff != NULL); + assert(pCelBuff != NULL); if (pCelBuff == NULL) return; assert(nCel > 0); diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 1cd6a3351..a09523c96 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -76,7 +76,7 @@ void ShowProgress(unsigned int uMsg) gbSomebodyWonGameKludge = FALSE; plrmsg_delay(TRUE); - /// ASSERT: assert(ghMainWnd); + assert(ghMainWnd); saveProc = SetWindowProc(DisableInputWndProc); interface_msg_pump(); @@ -114,7 +114,7 @@ void ShowProgress(unsigned int uMsg) FreeGameMem(); currlevel++; leveltype = gnLevelTypeTbl[currlevel]; - /// ASSERT: assert(plr[myplr].plrlevel == currlevel); + assert(plr[myplr].plrlevel == currlevel); IncProgress(); LoadGameLevel(FALSE, 0); IncProgress(); @@ -130,7 +130,7 @@ void ShowProgress(unsigned int uMsg) FreeGameMem(); currlevel--; leveltype = gnLevelTypeTbl[currlevel]; - /// ASSERT: assert(plr[myplr].plrlevel == currlevel); + assert(plr[myplr].plrlevel == currlevel); IncProgress(); LoadGameLevel(FALSE, 1); IncProgress(); @@ -185,7 +185,7 @@ void ShowProgress(unsigned int uMsg) FreeGameMem(); currlevel = plr[myplr].plrlevel; leveltype = gnLevelTypeTbl[currlevel]; - /// ASSERT: assert(plr[myplr].plrlevel == currlevel); + assert(plr[myplr].plrlevel == currlevel); IncProgress(); LoadGameLevel(FALSE, 6); IncProgress(); @@ -200,7 +200,7 @@ void ShowProgress(unsigned int uMsg) FreeGameMem(); currlevel = plr[myplr].plrlevel; leveltype = gnLevelTypeTbl[currlevel]; - /// ASSERT: assert(plr[myplr].plrlevel == currlevel); + assert(plr[myplr].plrlevel == currlevel); IncProgress(); LoadGameLevel(FALSE, 7); IncProgress(); @@ -215,20 +215,20 @@ void ShowProgress(unsigned int uMsg) FreeGameMem(); currlevel = plr[myplr].plrlevel; leveltype = gnLevelTypeTbl[currlevel]; - /// ASSERT: assert(plr[myplr].plrlevel == currlevel); + assert(plr[myplr].plrlevel == currlevel); IncProgress(); LoadGameLevel(FALSE, 0); IncProgress(); break; } - /// ASSERT: assert(ghMainWnd); + assert(ghMainWnd); PaletteFadeOut(8); FreeInterface(); saveProc = SetWindowProc(saveProc); - /// ASSERT: assert(saveProc == DisableInputWndProc); + assert(saveProc == DisableInputWndProc); NetSendCmdLocParam1(TRUE, CMD_PLAYER_JOINLEVEL, plr[myplr]._px, plr[myplr]._py, plr[myplr].plrlevel); plrmsg_delay(FALSE); @@ -248,7 +248,7 @@ void FreeInterface() void InitCutscene(unsigned int uMsg) { - /// ASSERT: assert(! sgpBackCel); + assert(!sgpBackCel); switch (uMsg) { case WM_DIABNEXTLVL: diff --git a/Source/inv.cpp b/Source/inv.cpp index 50b76d3fd..441d78e2a 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -134,7 +134,7 @@ void InvDrawSlotBack(int X, int Y, int W, int H) { BYTE *dst; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); dst = &gpBuffer[X + PitchTbl[Y]]; @@ -1710,15 +1710,13 @@ void SyncGetItem(int x, int y, int idx, WORD ci, int iseed) if (itemactive[i] == ii) { DeleteItem(itemactive[i], i); FindGetItem(idx, ci, iseed); - /// ASSERT: assert(FindGetItem(idx,ci,iseed) == -1); - FindGetItem(idx, ci, iseed); /* todo: replace with above */ + assert(FindGetItem(idx,ci,iseed) == -1); i = 0; } else { i++; } } - /// ASSERT: assert(FindGetItem(idx, ci, iseed) == -1); - FindGetItem(idx, ci, iseed); /* todo: replace with above */ + assert(FindGetItem(idx, ci, iseed) == -1); } } @@ -1847,9 +1845,7 @@ int InvPutItem(int pnum, int x, int y) } } - CanPut(x, y); //if (!CanPut(x, y)) { - // assertion_failed(1524, "C:\\Diablo\\Direct\\inv.cpp", "CanPut(x,y)"); - //} + assert(CanPut(x, y)); ii = itemavail[0]; dItem[x][y] = ii + 1; @@ -1916,7 +1912,7 @@ int SyncPutItem(int pnum, int x, int y, int idx, WORD icreateinfo, int iseed, in } } - CanPut(x, y); + assert(CanPut(x, y)); ii = itemavail[0]; dItem[x][y] = ii + 1; diff --git a/Source/items.cpp b/Source/items.cpp index fc4b0eba2..b162a2d08 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -580,7 +580,7 @@ void CalcPlrItemVals(int p, BOOL Loadgfx) d = plr[p]._pdir; - // TODO: Add debug assert here ( plr[p]._pNAnim[d] != NULL ) + assert(plr[p]._pNAnim[d]); plr[p]._pAnimData = plr[p]._pNAnim[d]; plr[p]._pAnimLen = plr[p]._pNFrames; @@ -2957,7 +2957,7 @@ void PrintUString(int x, int y, BOOL cjustflag, char *str, int col) void DrawULine(int y) { - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); #ifdef USE_ASM int yy; diff --git a/Source/lighting.cpp b/Source/lighting.cpp index eb368fba5..4a083214f 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -786,7 +786,7 @@ void FreeLightTable() void InitLightTable() { - /// ASSERT: assert(! pLightTbl); + assert(!pLightTbl); pLightTbl = DiabloAllocPtr(LIGHTSIZE); } diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 9860c8e9d..d7bc2f976 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -23,8 +23,8 @@ void GetDamageAmt(int i, int *mind, int *maxd) { int k, sl; - /// ASSERT: assert((DWORD)myplr < MAX_PLRS); - /// ASSERT: assert((DWORD)i < 64); + assert((DWORD)myplr < MAX_PLRS); + assert((DWORD)i < 64); sl = plr[myplr]._pSplLvl[i] + plr[myplr]._pISplLvlAdd; switch (i) { diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index e46e50826..c0ff46e0e 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -2318,7 +2318,7 @@ static void DrawZoom(int x, int y) wdt = SCREEN_WIDTH / 2; } - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); #ifdef USE_ASM __asm { @@ -2441,7 +2441,7 @@ void ClearScreenBuffer() { lock_buf(3); - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); #ifdef USE_ASM __asm { @@ -2604,8 +2604,8 @@ static void DoBlitScreen(DWORD dwX, DWORD dwY, DWORD dwWdt, DWORD dwHgt) HRESULT hDDVal; RECT SrcRect; - /// ASSERT: assert(! (dwX & 3)); - /// ASSERT: assert(! (dwWdt & 3)); + assert(!(dwX & 3)); + assert(!(dwWdt & 3)); if (lpDDSBackBuf != NULL) { SrcRect.left = dwX + SCREEN_X; diff --git a/Source/sync.cpp b/Source/sync.cpp index 7e33d9573..a630ff74c 100644 --- a/Source/sync.cpp +++ b/Source/sync.cpp @@ -27,7 +27,7 @@ DWORD sync_all_monsters(const BYTE *pbBuf, DWORD dwMaxLen) pHdr->bLevel = currlevel; pHdr->wLen = 0; SyncPlrInv(pHdr); - /// ASSERT: assert(dwMaxLen <= 0xffff); + assert(dwMaxLen <= 0xffff); sync_one_monster(); for (i = 0; i < nummonsters && dwMaxLen >= sizeof(TSyncMonster); i++) { @@ -168,7 +168,7 @@ void SyncPlrInv(TSyncHeader *pHdr) pHdr->bItemI = -1; } - /// ASSERT: assert((DWORD) sgnSyncPInv < NUM_INVLOC); + assert((DWORD)sgnSyncPInv < NUM_INVLOC); pItem = &plr[myplr].InvBody[sgnSyncPInv]; if (pItem->_itype != ITYPE_NONE) { pHdr->bPInvLoc = sgnSyncPInv; @@ -215,7 +215,7 @@ DWORD sync_update(int pnum, const BYTE *pbBuf) pbBuf += sizeof(TSyncMonster); } - /// ASSERT: assert(wLen == 0); + assert(wLen == 0); return pHdr->wLen + sizeof(*pHdr); } diff --git a/Source/town.cpp b/Source/town.cpp index 18c25a1cd..43234ac73 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -7,7 +7,7 @@ */ void town_clear_upper_buf(BYTE *pBuff) { - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); #ifdef USE_ASM __asm { @@ -74,7 +74,7 @@ void town_clear_upper_buf(BYTE *pBuff) */ void town_clear_low_buf(BYTE *pBuff) { - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); #ifdef USE_ASM __asm { @@ -430,7 +430,7 @@ void town_draw_clipped_town(BYTE *pBuff, int sx, int sy, int dx, int dy, int efl int mi, px, py; char bv; - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); pBuff = &gpBuffer[dx + PitchTbl[dy]]; @@ -1228,7 +1228,7 @@ void T_DrawZoom(int x, int y) break; } - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); gpBufEnd = &gpBuffer[PitchTbl[-17 + SCREEN_Y]]; for (i = 0; i < 7; i++) { town_draw_upper(x, y, sx, sy, chunks, i, 0); @@ -1240,7 +1240,7 @@ void T_DrawZoom(int x, int y) sx += 32; sy += 16; } - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); gpBufEnd = &gpBuffer[PitchTbl[160 + SCREEN_Y]]; for (i = 0; i < blocks; i++) { town_draw_lower(x, y, sx, sy, chunks, 0); @@ -1277,7 +1277,7 @@ void T_DrawZoom(int x, int y) wdt = SCREEN_WIDTH / 2; } - /// ASSERT: assert(gpBuffer); + assert(gpBuffer); #ifdef USE_ASM __asm { From 8c3ec9123265edd5f1c87da6f3a2e389b1e6830d Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 13 Apr 2020 19:36:07 +0200 Subject: [PATCH 09/19] Use enums in the ObjTypeConv map --- Source/objdat.cpp | 228 +++++++++++++++++++++++----------------------- Source/objdat.h | 2 +- 2 files changed, 115 insertions(+), 115 deletions(-) diff --git a/Source/objdat.cpp b/Source/objdat.cpp index 3fd9cd1d6..4c4911ae5 100644 --- a/Source/objdat.cpp +++ b/Source/objdat.cpp @@ -1,120 +1,120 @@ #include "all.h" /** Maps from dun_object_id to object_id. */ -int ObjTypeConv[113] = { - 0, - 4, - 20, - 21, - 22, - 24, - 11, - 12, - 13, - 0, - 0, - 0, - 0, - 0, - 25, - 41, - 26, - 0, - 8, - 9, - 10, - 80, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 49, - 0, - 0, - 0, - 0, - 0, - 84, - 85, - 3, - 14, - 15, - 16, - 17, - 18, - 19, - 0, - 0, - 0, - 0, - 0, - 0, - 28, - 0, - 53, - 54, - 36, - 37, - 38, - 39, - 40, - 0, - 0, - 0, - 0, - 0, - 27, - 0, - 0, - 0, - 0, - 29, - 30, - 31, - 32, - 33, - 34, - 35, - 5, - 5, - 5, - 6, - 6, - 6, - 7, - 7, - 7, - 0, - 0, - 0, - 0, - 0, - 73, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 83, - 0, - 0, - 89, - 90, - 47, - 46, - 94 +int ObjTypeConv[] = { + OBJ_L1LIGHT, + OBJ_LEVER, + OBJ_CRUX1, + OBJ_CRUX2, + OBJ_CRUX3, + OBJ_ANGEL, + OBJ_BANNERL, + OBJ_BANNERM, + OBJ_BANNERR, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_BOOK2L, + OBJ_BOOK2R, + OBJ_BCROSS, + OBJ_L1LIGHT, + OBJ_CANDLE1, + OBJ_CANDLE2, + OBJ_CANDLEO, + OBJ_CAULDRON, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_GOATSHRINE, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_MCIRCLE1, + OBJ_MCIRCLE2, + OBJ_SKFIRE, + OBJ_SKPILE, + OBJ_SKSTICK1, + OBJ_SKSTICK2, + OBJ_SKSTICK3, + OBJ_SKSTICK4, + OBJ_SKSTICK5, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_SWITCHSKL, + OBJ_L1LIGHT, + OBJ_TRAPL, + OBJ_TRAPR, + OBJ_TORTURE1, + OBJ_TORTURE2, + OBJ_TORTURE3, + OBJ_TORTURE4, + OBJ_TORTURE5, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_NUDEW2R, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_TNUDEM1, + OBJ_TNUDEM2, + OBJ_TNUDEM3, + OBJ_TNUDEM4, + OBJ_TNUDEW1, + OBJ_TNUDEW2, + OBJ_TNUDEW3, + OBJ_CHEST1, + OBJ_CHEST1, + OBJ_CHEST1, + OBJ_CHEST2, + OBJ_CHEST2, + OBJ_CHEST2, + OBJ_CHEST3, + OBJ_CHEST3, + OBJ_CHEST3, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_PEDISTAL, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_ALTBOY, + OBJ_L1LIGHT, + OBJ_L1LIGHT, + OBJ_WARARMOR, + OBJ_WARWEAP, + OBJ_TORCHR2, + OBJ_TORCHL2, + OBJ_MUSHPATCH, }; /** Contains the data related to each object ID. */ diff --git a/Source/objdat.h b/Source/objdat.h index ff879f15c..29c33bc19 100644 --- a/Source/objdat.h +++ b/Source/objdat.h @@ -2,7 +2,7 @@ #ifndef __OBJDAT_H__ #define __OBJDAT_H__ -extern int ObjTypeConv[113]; +extern int ObjTypeConv[]; extern ObjDataStruct AllObjects[99]; extern char *ObjMasterLoadList[56]; From 10be0c66e01c5822d93fc5383f9c30fe71bd171a Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 13 Apr 2020 20:32:05 +0200 Subject: [PATCH 10/19] Correct ObjTypeConv --- Source/objdat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/objdat.cpp b/Source/objdat.cpp index 4c4911ae5..712bc0eff 100644 --- a/Source/objdat.cpp +++ b/Source/objdat.cpp @@ -32,7 +32,7 @@ int ObjTypeConv[] = { OBJ_L1LIGHT, OBJ_L1LIGHT, OBJ_L1LIGHT, - OBJ_GOATSHRINE, + OBJ_FLAMEHOLE, OBJ_L1LIGHT, OBJ_L1LIGHT, OBJ_L1LIGHT, From 7873bd4356b27933cb75a7ad78bbc9b86ae028ef Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Tue, 14 Apr 2020 00:34:12 +0200 Subject: [PATCH 11/19] minitext: fix variable names of minitext.cpp The variable names were mixed up. sgLastScroll -> qtextSpd scrolltexty -> qtextDelay qtextSpd -> sgLastScroll --- Source/minitext.cpp | 28 ++++++++++++++-------------- Source/minitext.h | 2 -- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 54ca65f17..3484b31af 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -7,10 +7,10 @@ int qtexty; char *qtextptr; -int qtextSpd; -BOOLEAN qtextflag; -int scrolltexty; int sgLastScroll; +BOOLEAN qtextflag; +int qtextDelay; +int qtextSpd; BYTE *pMedTextCels; BYTE *pTextBoxCels; @@ -72,9 +72,9 @@ void InitQTextMsg(int m) qtextptr = alltext[m].txtstr; qtextflag = TRUE; qtexty = 500; - sgLastScroll = qscroll_spd_tbl[alltext[m].txtspd - 1]; - scrolltexty = sgLastScroll; - qtextSpd = GetTickCount(); + qtextSpd = qscroll_spd_tbl[alltext[m].txtspd - 1]; + qtextDelay = qtextSpd; + sgLastScroll = GetTickCount(); } PlaySFX(alltext[m].sfxnr); } @@ -272,17 +272,17 @@ void DrawQText() currTime = GetTickCount(); while (1) { - if (sgLastScroll <= 0) { + if (qtextSpd <= 0) { qtexty--; - qtexty += sgLastScroll; + qtexty += qtextSpd; } else { - scrolltexty--; - if (scrolltexty != 0) { + qtextDelay--; + if (qtextDelay != 0) { qtexty--; } } - if (scrolltexty == 0) { - scrolltexty = sgLastScroll; + if (qtextDelay == 0) { + qtextDelay = qtextSpd; } if (qtexty <= 209) { qtexty += 38; @@ -292,8 +292,8 @@ void DrawQText() } break; } - qtextSpd += 50; - if (currTime - qtextSpd >= 0x7FFFFFFF) { + sgLastScroll += 50; + if (currTime - sgLastScroll >= 0x7FFFFFFF) { break; } } diff --git a/Source/minitext.h b/Source/minitext.h index 568e51b6f..27b740e5c 100644 --- a/Source/minitext.h +++ b/Source/minitext.h @@ -8,9 +8,7 @@ extern int qtexty; extern char *qtextptr; -extern int qtextSpd; extern BOOLEAN qtextflag; -extern int scrolltexty; extern BYTE *pMedTextCels; extern BYTE *pTextBoxCels; From 23dca91a95b57eddb8a27ca099cfb0c9e53a8210 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Tue, 14 Apr 2020 05:25:48 +0200 Subject: [PATCH 12/19] docs: add function documentation to appfat.cpp --- Source/appfat.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/Source/appfat.cpp b/Source/appfat.cpp index 90ad6f0ae..b6d38c35a 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -55,6 +55,9 @@ LONG __stdcall BreakFilter(PEXCEPTION_POINTERS pExc) } #endif +/** + * @brief Returns a formatted error message based on the given error code. + */ char *GetErrorStr(DWORD error_code) { int size; @@ -462,11 +465,17 @@ void TraceErrorDS(HRESULT hError, char *pszBuffer, DWORD dwMaxChars) strncpy(pszBuffer, szError, dwMaxChars); } +/** + * @brief Returns a formatted error message of the last error. + */ char *TraceLastError() { return GetErrorStr(GetLastError()); } +/** + * @brief Terminates the game and displays an error message box. + */ void __cdecl app_fatal(const char *pszFmt, ...) { va_list va; @@ -487,6 +496,9 @@ void __cdecl app_fatal(const char *pszFmt, ...) ExitProcess(1); } +/** + * @brief Displays an error message box based on the given format string and variable argument list. + */ void MsgBox(const char *pszFmt, va_list va) { char Text[256]; @@ -497,6 +509,9 @@ void MsgBox(const char *pszFmt, va_list va) MessageBox(ghMainWnd, Text, "ERROR", MB_TASKMODAL | MB_ICONHAND); } +/** + * @brief Cleans up after a fatal application error. + */ void FreeDlg() { if (terminating && cleanup_thread_id != GetCurrentThreadId()) @@ -516,6 +531,9 @@ void FreeDlg() ShowCursor(TRUE); } +/** + * @brief Displays a warning message box based on the given formatted error message. + */ void __cdecl DrawDlg(char *pszFmt, ...) { char text[256]; @@ -534,6 +552,9 @@ void assert_fail(int nLineNo, const char *pszFile, const char *pszFail) } #endif +/** + * @brief Terminates the game with a DirectDraw assertion message box. + */ void DDErrMsg(DWORD error_code, int log_line_nr, char *log_file_path) { char *msg; @@ -544,6 +565,9 @@ void DDErrMsg(DWORD error_code, int log_line_nr, char *log_file_path) } } +/** + * @brief Terminates the game with a DirectSound assertion message box. + */ void DSErrMsg(DWORD error_code, int log_line_nr, char *log_file_path) { char *msg; @@ -554,6 +578,9 @@ void DSErrMsg(DWORD error_code, int log_line_nr, char *log_file_path) } } +/** + * @brief Centres the given dialog box. + */ void center_window(HWND hDlg) { LONG w, h; @@ -574,6 +601,9 @@ void center_window(HWND hDlg) } } +/** + * @brief Callback function which processes messages sent to the given dialog box. + */ static BOOL CALLBACK FuncDlg(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { @@ -594,7 +624,10 @@ static BOOL CALLBACK FuncDlg(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) return TRUE; } -void ErrDlg(int template_id, DWORD error_code, char *log_file_path, int log_line_nr) +/** + * @brief Terminates the game and displays an error dialog box based on the given dialog_id. + */ +void ErrDlg(int dialog_id, DWORD error_code, char *log_file_path, int log_line_nr) { char *size; LPARAM dwInitParam[128]; @@ -606,12 +639,15 @@ void ErrDlg(int template_id, DWORD error_code, char *log_file_path, int log_line log_file_path = size + 1; wsprintf((LPSTR)dwInitParam, "%s\nat: %s line %d", GetErrorStr(error_code), log_file_path, log_line_nr); - if (DialogBoxParam(ghInst, MAKEINTRESOURCE(template_id), ghMainWnd, FuncDlg, (LPARAM)dwInitParam) == -1) - app_fatal("ErrDlg: %d", template_id); + if (DialogBoxParam(ghInst, MAKEINTRESOURCE(dialog_id), ghMainWnd, FuncDlg, (LPARAM)dwInitParam) == -1) + app_fatal("ErrDlg: %d", dialog_id); app_fatal(NULL); } +/** + * @brief Sets the text of the given dialog. + */ static void TextDlg(HWND hDlg, char *text) { center_window(hDlg); @@ -620,7 +656,10 @@ static void TextDlg(HWND hDlg, char *text) SetDlgItemText(hDlg, 1000, text); } -void ErrOkDlg(int template_id, DWORD error_code, char *log_file_path, int log_line_nr) +/** + * @brief Displays a warning dialog box based on the given dialog_id and error code. + */ +void ErrOkDlg(int dialog_id, DWORD error_code, char *log_file_path, int log_line_nr) { char *size; LPARAM dwInitParam[128]; @@ -630,9 +669,12 @@ void ErrOkDlg(int template_id, DWORD error_code, char *log_file_path, int log_li log_file_path = size + 1; wsprintf((LPSTR)dwInitParam, "%s\nat: %s line %d", GetErrorStr(error_code), log_file_path, log_line_nr); - DialogBoxParam(ghInst, MAKEINTRESOURCE(template_id), ghMainWnd, FuncDlg, (LPARAM)dwInitParam); + DialogBoxParam(ghInst, MAKEINTRESOURCE(dialog_id), ghMainWnd, FuncDlg, (LPARAM)dwInitParam); } +/** + * @brief Terminates the game with a file not found error dialog. + */ void FileErrDlg(const char *error) { FreeDlg(); @@ -646,6 +688,9 @@ void FileErrDlg(const char *error) app_fatal(NULL); } +/** + * @brief Terminates the game with an out of disk space error dialog. + */ void DiskFreeDlg(char *error) { FreeDlg(); @@ -656,6 +701,9 @@ void DiskFreeDlg(char *error) app_fatal(NULL); } +/** + * @brief Terminates the game with an insert CD error dialog. + */ BOOL InsertCDDlg() { int nResult; @@ -671,6 +719,9 @@ BOOL InsertCDDlg() return nResult == IDOK; } +/** + * @brief Terminates the game with a read-only directory error dialog. + */ void DirErrorDlg(char *error) { FreeDlg(); From 452d6d25cc94fe918a1ff522b3770198f3e152c0 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Tue, 14 Apr 2020 06:51:06 +0200 Subject: [PATCH 13/19] docs: add function documentation to automap.cpp --- Source/automap.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Source/automap.cpp b/Source/automap.cpp index 557f12ec7..911bc20ce 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -45,6 +45,9 @@ int AmLine4; #define MAPFLAG_DIRT 0x40 #define MAPFLAG_STAIRS 0x80 +/** + * @brief Initializes the automap. + */ void InitAutomapOnce() { automapflag = FALSE; @@ -56,6 +59,9 @@ void InitAutomapOnce() AmLine4 = 2; } +/** + * @brief Loads the mapping between tile IDs and automap shapes. + */ void InitAutomap() { BYTE b1, b2; @@ -114,6 +120,9 @@ void InitAutomap() } } +/** + * @brief Displays the automap. + */ void StartAutomap() { AutoMapXOfs = 0; @@ -121,30 +130,45 @@ void StartAutomap() automapflag = TRUE; } +/** + * @brief Scrolls the automap upwards. + */ void AutomapUp() { AutoMapXOfs--; AutoMapYOfs--; } +/** + * @brief Scrolls the automap downwards. + */ void AutomapDown() { AutoMapXOfs++; AutoMapYOfs++; } +/** + * @brief Scrolls the automap leftwards. + */ void AutomapLeft() { AutoMapXOfs--; AutoMapYOfs++; } +/** + * @brief Scrolls the automap rightwards. + */ void AutomapRight() { AutoMapXOfs++; AutoMapYOfs--; } +/** + * @brief Increases the zoom level of the automap. + */ void AutomapZoomIn() { if (AutoMapScale < 200) { @@ -157,6 +181,9 @@ void AutomapZoomIn() } } +/** + * @brief Decreases the zoom level of the automap. + */ void AutomapZoomOut() { if (AutoMapScale > 50) { @@ -169,6 +196,9 @@ void AutomapZoomOut() } } +/** + * @brief Renders the automap on screen. + */ void DrawAutomap() { int cells; @@ -254,6 +284,9 @@ void DrawAutomap() DrawAutomapText(); } +/** + * @brief Renders the given automap shape at the specified screen coordinates. + */ void DrawAutomapTile(int sx, int sy, WORD automap_type) { BOOL do_vert; @@ -439,6 +472,9 @@ void DrawAutomapTile(int sx, int sy, WORD automap_type) } } +/** + * @brief Renders an arrow on the automap, centered on and facing the direction of the player. + */ void DrawAutomapPlr() { int px, py; @@ -511,6 +547,9 @@ void DrawAutomapPlr() } } +/** + * @brief Returns the automap shape at the given coordinate. + */ WORD GetAutomapType(int x, int y, BOOL view) { WORD rv; @@ -552,6 +591,9 @@ WORD GetAutomapType(int x, int y, BOOL view) return rv; } +/** + * @brief Renders game info, such as the name of the current level, and in multi player the name of the game and the game password. + */ void DrawAutomapText() { char desc[256]; @@ -575,6 +617,9 @@ void DrawAutomapText() } } +/** + * @brief Marks the given coordinate as within view on the automap. + */ void SetAutomapView(int x, int y) { WORD maptype, solid; @@ -647,6 +692,9 @@ void SetAutomapView(int x, int y) } } +/** + * @brief Resets the zoom level of the automap. + */ void AutomapZoomReset() { AutoMapXOfs = 0; From 46224337d8ee5353379f9dba7891b990f13672b5 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 14 Apr 2020 12:29:47 +0200 Subject: [PATCH 14/19] Fix bin diff --- Source/inv.cpp | 12 ++++++++---- Source/items.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index 441d78e2a..618fc8289 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1710,13 +1710,15 @@ void SyncGetItem(int x, int y, int idx, WORD ci, int iseed) if (itemactive[i] == ii) { DeleteItem(itemactive[i], i); FindGetItem(idx, ci, iseed); - assert(FindGetItem(idx,ci,iseed) == -1); + /// ASSERT: assert(FindGetItem(idx,ci,iseed) == -1); + FindGetItem(idx, ci, iseed); /* todo: replace with above */ i = 0; } else { i++; } } - assert(FindGetItem(idx, ci, iseed) == -1); + /// ASSERT: assert(FindGetItem(idx, ci, iseed) == -1); + FindGetItem(idx, ci, iseed); /* todo: replace with above */ } } @@ -1845,7 +1847,9 @@ int InvPutItem(int pnum, int x, int y) } } - assert(CanPut(x, y)); + CanPut(x, y); //if (!CanPut(x, y)) { + // assertion_failed(1524, "C:\\Diablo\\Direct\\inv.cpp", "CanPut(x,y)"); + //} ii = itemavail[0]; dItem[x][y] = ii + 1; @@ -1912,7 +1916,7 @@ int SyncPutItem(int pnum, int x, int y, int idx, WORD icreateinfo, int iseed, in } } - assert(CanPut(x, y)); + CanPut(x, y); ii = itemavail[0]; dItem[x][y] = ii + 1; diff --git a/Source/items.cpp b/Source/items.cpp index b162a2d08..c49429b85 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1680,7 +1680,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) goe = 0; if (!onlygood && random_(0, 3)) onlygood = TRUE; - if (pre == 0) { + if (!pre) { nt = 0; for (j = 0; PL_Prefix[j].PLPower != -1; j++) { if (flgs & PL_Prefix[j].PLIType) { From fe82c0b1f17077b3d9a4586cc78fe2be8970f83b Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Wed, 15 Apr 2020 16:52:42 +0200 Subject: [PATCH 15/19] Clean up GetItemPower Thanks @tsunamistate for bringing attention to this --- Source/items.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/items.cpp b/Source/items.cpp index c49429b85..d1b93fb0a 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1694,7 +1694,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood) } } } - if (nl != 0) { + if (nt != 0) { preidx = l[random_(23, nt)]; sprintf(istr, "%s %s", PL_Prefix[preidx].PLName, item[i]._iIName); strcpy(item[i]._iIName, istr); From 0186d85923f4ef65ebf2270abcfc42a10e876f44 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 25 Apr 2020 17:06:58 +0200 Subject: [PATCH 16/19] makefile: run clean on subprojects when invoking `make clean` --- MakefileVC | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MakefileVC b/MakefileVC index 24c0cdc5c..af480a19a 100644 --- a/MakefileVC +++ b/MakefileVC @@ -86,5 +86,8 @@ diablo.res: Diablo.rc clean: @$(RM) -v $(OBJS) vc60.idb vc60.pdb Diablo.pdb Diablo.pch + make -C DiabloUI clean + make -C 3rdParty/Storm clean + make -C 3rdParty/PKWare clean .PHONY: clean all From e6fa244fa7ae155932a17201d16d8826f86531e5 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sun, 26 Apr 2020 19:25:50 +0200 Subject: [PATCH 17/19] items: add BUGFIX comment for SaveItemPower --- Source/items.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/items.cpp b/Source/items.cpp index d1b93fb0a..12d44d503 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1441,7 +1441,7 @@ void SaveItemPower(int i, int power, int param1, int param2, int minval, int max break; case IPL_SPELL: item[i]._iSpell = param1; - item[i]._iCharges = param1; + item[i]._iCharges = param1; // BUGFIX: should be param2. This code was correct in v1.04, and the bug was introduced between 1.04 and 1.09b. item[i]._iMaxCharges = param2; break; case IPL_FIREDAM: From b0a8a384629005f1aba5078cbe8f7e6bb0ae3960 Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 20 Apr 2020 00:25:01 +0200 Subject: [PATCH 18/19] clean magic numbers --- Source/control.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index fd5ff1ffa..87412648a 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1149,7 +1149,7 @@ void DrawLifeFlask() filled = 11; filled += 2; - DrawFlask(pLifeBuff, 88, 277, gpBuffer, SCREENXY(PANEL_LEFT + 109, PANEL_TOP - 13), filled); + DrawFlask(pLifeBuff, 88, 88 * 3 + 13, gpBuffer, SCREENXY(PANEL_LEFT + 109, PANEL_TOP - 13), filled); if (filled != 13) DrawFlask(pBtmBuff, PANEL_WIDTH, PANEL_WIDTH * (filled + 3) + 109, gpBuffer, SCREENXY(PANEL_LEFT + 109, PANEL_TOP - 13 + filled), 13 - filled); } @@ -1187,7 +1187,7 @@ void DrawManaFlask() filled = 11; filled += 2; - DrawFlask(pManaBuff, 88, 277, gpBuffer, SCREENXY(PANEL_LEFT + 475, PANEL_TOP - 13), filled); + DrawFlask(pManaBuff, 88, 88 * 3 + 13, gpBuffer, SCREENXY(PANEL_LEFT + 475, PANEL_TOP - 13), filled); if (filled != 13) DrawFlask(pBtmBuff, PANEL_WIDTH, PANEL_WIDTH * (filled + 3) + 475, gpBuffer, SCREENXY(PANEL_LEFT + 475, PANEL_TOP - 13 + filled), 13 - filled); } @@ -1233,9 +1233,9 @@ void UpdateManaFlask() if (filled > 69) filled = 69; if (filled != 69) - SetFlaskHeight(pManaBuff, 16, 85 - filled, 96 + PANEL_X + 368, PANEL_Y); + SetFlaskHeight(pManaBuff, 16, 85 - filled, PANEL_X + 464, PANEL_Y); if (filled != 0) - DrawPanelBox(96 + 368, 85 - filled, 88, filled, 96 + PANEL_X + 368, PANEL_Y + 69 - filled); + DrawPanelBox(464, 85 - filled, 88, filled, PANEL_X + 464, PANEL_Y + 69 - filled); DrawSpell(); } From 7e45f8bcc89340f51ad0717bcc3abab329d70b53 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 26 Apr 2020 19:45:52 +0200 Subject: [PATCH 19/19] More cleanups --- Source/mainmenu.cpp | 8 +++---- Source/mainmenu.h | 2 +- Source/portal.cpp | 2 +- Source/themes.cpp | 8 +++---- Source/towners.cpp | 52 ++++++++++++++++++++++----------------------- Source/towners.h | 2 +- Source/track.cpp | 2 +- Source/trigs.cpp | 48 ++++++++++++++++++++++------------------- defs.h | 2 ++ 9 files changed, 66 insertions(+), 60 deletions(-) diff --git a/Source/mainmenu.cpp b/Source/mainmenu.cpp index 57b2f6a51..2f2de418b 100644 --- a/Source/mainmenu.cpp +++ b/Source/mainmenu.cpp @@ -32,7 +32,7 @@ void __stdcall mainmenu_change_name(int arg1, int arg2, int arg3, int arg4, char pfile_rename_hero(name_1, name_2); } -int __stdcall mainmenu_select_hero_dialog( +BOOL __stdcall mainmenu_select_hero_dialog( const _SNETPROGRAMDATA *client_info, const _SNETPLAYERDATA *user_info, const _SNETUIDATA *ui_info, @@ -72,7 +72,7 @@ int __stdcall mainmenu_select_hero_dialog( } if (dlgresult == SELHERO_PREVIOUS) { SErrSetLastError(1223); - return 0; + return FALSE; } pfile_create_player_description(cdesc, cdlen); @@ -85,7 +85,7 @@ int __stdcall mainmenu_select_hero_dialog( if (cname && clen) SStrCopy(cname, gszHero, clen); - return 1; + return TRUE; } void mainmenu_loop() @@ -126,7 +126,7 @@ void mainmenu_loop() done = TRUE; break; } - } while (done == FALSE); + } while (!done); music_stop(); } diff --git a/Source/mainmenu.h b/Source/mainmenu.h index dc0ddb341..112676219 100644 --- a/Source/mainmenu.h +++ b/Source/mainmenu.h @@ -10,7 +10,7 @@ extern char gszHero[16]; void mainmenu_refresh_music(); void __stdcall mainmenu_change_name(int arg1, int arg2, int arg3, int arg4, char *name_1, char *name_2); -int __stdcall mainmenu_select_hero_dialog( +BOOL __stdcall mainmenu_select_hero_dialog( const _SNETPROGRAMDATA *client_info, const _SNETPLAYERDATA *user_info, const _SNETUIDATA *ui_info, diff --git a/Source/portal.cpp b/Source/portal.cpp index 88df7ac7d..b4b1a709d 100644 --- a/Source/portal.cpp +++ b/Source/portal.cpp @@ -109,7 +109,7 @@ void RemovePortalMissile(int id) dFlags[missile[mi]._mix][missile[mi]._miy] &= ~BFLAG_MISSILE; dMissile[missile[mi]._mix][missile[mi]._miy] = 0; - if (portal[id].level) + if (portal[id].level != 0) AddUnLight(missile[mi]._mlid); DeleteMissile(mi, i); diff --git a/Source/themes.cpp b/Source/themes.cpp index 604666d6e..45e40cc2c 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -24,7 +24,7 @@ BOOL bCrossFlag; int ThemeGood[4] = { THEME_GOATSHRINE, THEME_SHRINE, THEME_SKELROOM, THEME_LIBRARY }; -int trm5x[25] = { +int trm5x[] = { -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, @@ -32,7 +32,7 @@ int trm5x[25] = { -2, -1, 0, 1, 2 }; -int trm5y[25] = { +int trm5y[] = { -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, @@ -40,13 +40,13 @@ int trm5y[25] = { 2, 2, 2, 2, 2 }; -int trm3x[9] = { +int trm3x[] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 }; -int trm3y[9] = { +int trm3y[] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 diff --git a/Source/towners.cpp b/Source/towners.cpp index 7364cda8d..6e3ca8d27 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -8,13 +8,13 @@ DWORD sgdwCowClicks; BOOL bannerflag; BOOL boyloadflag; BYTE *pCowCels; -TownerStruct towner[16]; +TownerStruct towner[NUM_TOWNERS]; #ifndef SPAWN const int snSFX[3][NUM_CLASSES] = { { PS_WARR52, PS_ROGUE52, PS_MAGE52 }, { PS_WARR49, PS_ROGUE49, PS_MAGE49 }, - { PS_WARR50, PS_ROGUE50, PS_MAGE50 } + { PS_WARR50, PS_ROGUE50, PS_MAGE50 }, }; #endif @@ -86,9 +86,9 @@ char AnimOrder[6][148] = { 1, 2, 1, 19, 18, 19, 1, 2, 1, 2, 3, -1 } }; -int TownCowX[3] = { 58, 56, 59 }; -int TownCowY[3] = { 16, 14, 20 }; -int TownCowDir[3] = { 1, 3, 4 }; +int TownCowX[] = { 58, 56, 59 }; +int TownCowY[] = { 16, 14, 20 }; +int TownCowDir[] = { DIR_SW, DIR_NW, DIR_N }; int cowoffx[8] = { -1, 0, -1, -1, -1, 0, -1, -1 }; int cowoffy[8] = { -1, -1, -1, 0, -1, -1, -1, 0 }; QuestTalkData Qtalklist[] = { @@ -197,7 +197,7 @@ void InitSmith() { int i; - InitTownerInfo(numtowners, 96, 1, TOWN_SMITH, 62, 63, 0, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_SMITH, 62, 63, 0, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\Smith\\SmithN.CEL", NULL); for (i = 0; i < 8; i++) { @@ -214,7 +214,7 @@ void InitBarOwner() int i; bannerflag = FALSE; // unused - InitTownerInfo(numtowners, 96, 1, TOWN_TAVERN, 55, 62, 3, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_TAVERN, 55, 62, 3, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\TwnF\\TwnFN.CEL", NULL); for (i = 0; i < 8; i++) { @@ -230,7 +230,7 @@ void InitTownDead() { int i; - InitTownerInfo(numtowners, 96, 1, TOWN_DEADGUY, 24, 32, -1, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_DEADGUY, 24, 32, -1, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\Butch\\Deadguy.CEL", NULL); for (i = 0; i < 8; i++) { @@ -246,7 +246,7 @@ void InitWitch() { int i; - InitTownerInfo(numtowners, 96, 1, TOWN_WITCH, 80, 20, 5, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_WITCH, 80, 20, 5, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\TownWmn1\\Witch.CEL", NULL); for (i = 0; i < 8; i++) { @@ -262,7 +262,7 @@ void InitBarmaid() { int i; - InitTownerInfo(numtowners, 96, 1, TOWN_BMAID, 43, 66, -1, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_BMAID, 43, 66, -1, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\TownWmn1\\WmnN.CEL", NULL); for (i = 0; i < 8; i++) { @@ -279,7 +279,7 @@ void InitBoy() int i; boyloadflag = TRUE; - InitTownerInfo(numtowners, 96, 1, TOWN_PEGBOY, 11, 53, -1, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_PEGBOY, 11, 53, -1, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\TownBoy\\PegKid1.CEL", NULL); for (i = 0; i < 8; i++) { @@ -295,7 +295,7 @@ void InitHealer() { int i; - InitTownerInfo(numtowners, 96, 1, TOWN_HEALER, 55, 79, 1, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_HEALER, 55, 79, 1, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\Healer\\Healer.CEL", NULL); for (i = 0; i < 8; i++) { @@ -311,7 +311,7 @@ void InitTeller() { int i; - InitTownerInfo(numtowners, 96, 1, TOWN_STORY, 62, 71, 2, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_STORY, 62, 71, 2, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\Strytell\\Strytell.CEL", NULL); for (i = 0; i < 8; i++) { @@ -327,7 +327,7 @@ void InitDrunk() { int i; - InitTownerInfo(numtowners, 96, 1, TOWN_DRUNK, 71, 84, 4, 10); + InitTownerInfo(numtowners, 96, TRUE, TOWN_DRUNK, 71, 84, 4, 10); InitQstSnds(numtowners); towner[numtowners]._tNData = LoadFileInMem("Towners\\Drunk\\TwnDrunk.CEL", NULL); for (i = 0; i < 8; i++) { @@ -351,22 +351,22 @@ void InitCows() x = TownCowX[i]; y = TownCowY[i]; dir = TownCowDir[i]; - InitTownerInfo(numtowners, 128, 0, TOWN_COW, TownCowX[i], TownCowY[i], -1, 10); + InitTownerInfo(numtowners, 128, FALSE, TOWN_COW, x, y, -1, 10); towner[numtowners]._tNData = pCowCels; SetTownerGPtrs(towner[numtowners]._tNData, towner[numtowners]._tNAnim); towner[numtowners]._tNFrames = 12; NewTownerAnim(numtowners, towner[numtowners]._tNAnim[dir], towner[numtowners]._tNFrames, 3); towner[numtowners]._tAnimFrame = random_(0, 11) + 1; - towner[numtowners]._tSelFlag = 1; + towner[numtowners]._tSelFlag = TRUE; strcpy(towner[numtowners]._tName, "Cow"); xo = x + cowoffx[dir]; yo = y + cowoffy[dir]; - if (!dMonster[x][yo]) + if (dMonster[x][yo] == 0) dMonster[x][yo] = -(numtowners + 1); - if (!dMonster[xo][y]) + if (dMonster[xo][y] == 0) dMonster[xo][y] = -(numtowners + 1); - if (!dMonster[xo][yo]) + if (dMonster[xo][yo] == 0) dMonster[xo][yo] = -(numtowners + 1); numtowners++; @@ -379,7 +379,7 @@ void InitTowners() boyloadflag = FALSE; InitSmith(); InitHealer(); - if (quests[Q_BUTCHER]._qactive && quests[Q_BUTCHER]._qactive != QUEST_DONE) + if (quests[Q_BUTCHER]._qactive != QUEST_NOTAVAIL && quests[Q_BUTCHER]._qactive != QUEST_DONE) InitTownDead(); InitBarOwner(); InitTeller(); @@ -394,7 +394,7 @@ void FreeTownerGFX() { int i; - for (i = 0; i < 16; i++) { + for (i = 0; i < NUM_TOWNERS; i++) { if (towner[i]._tNData == pCowCels) { towner[i]._tNData = NULL; } else if (towner[i]._tNData) { @@ -410,7 +410,7 @@ void TownCtrlMsg(int i) int p; int dx, dy; - if (towner[i]._tbtcnt) { + if (towner[i]._tbtcnt != 0) { p = towner[i]._tVar1; dx = abs(towner[i]._tx - plr[p]._px); dy = abs(towner[i]._ty - plr[p]._py); @@ -519,7 +519,7 @@ void ProcessTowners() { int i, ao; - for (i = 0; i < 16; i++) { + for (i = 0; i < NUM_TOWNERS; i++) { switch (towner[i]._ttype) { case TOWN_SMITH: TownBlackSmith(); @@ -787,13 +787,13 @@ void TalkToTowner(int p, int t) RemoveInvItem(p, i); quests[Q_MUSHROOM]._qactive = QUEST_ACTIVE; quests[Q_MUSHROOM]._qlog = TRUE; - quests[Q_MUSHROOM]._qvar1 = 2; + quests[Q_MUSHROOM]._qvar1 = QS_TOMEGIVEN; towner[t]._tbtcnt = 150; towner[t]._tVar1 = p; InitQTextMsg(TEXT_MUSH8); towner[t]._tMsgSaid = TRUE; } else if (quests[Q_MUSHROOM]._qactive == QUEST_ACTIVE) { - if (quests[Q_MUSHROOM]._qvar1 >= 2 && quests[Q_MUSHROOM]._qvar1 <= 4) { + if (quests[Q_MUSHROOM]._qvar1 >= QS_TOMEGIVEN && quests[Q_MUSHROOM]._qvar1 <= QS_MUSHPICKED) { if (PlrHasItem(p, IDI_MUSHROOM, i) != NULL) { RemoveInvItem(p, i); quests[Q_MUSHROOM]._qvar1 = 5; @@ -874,7 +874,7 @@ void TalkToTowner(int p, int t) RemoveInvItem(p, i); SpawnQuestItem(IDI_SPECELIX, towner[t]._tx, towner[t]._ty + 1, 0, 0); InitQTextMsg(TEXT_MUSH4); - quests[Q_MUSHROOM]._qvar1 = 7; + quests[Q_MUSHROOM]._qvar1 = QS_BRAINGIVEN; Qtalklist[TOWN_HEALER]._qblkm = -1; } } diff --git a/Source/towners.h b/Source/towners.h index 4fe06a318..ea01d016f 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -2,7 +2,7 @@ #ifndef __TOWNERS_H__ #define __TOWNERS_H__ -extern TownerStruct towner[16]; +extern TownerStruct towner[NUM_TOWNERS]; int GetActiveTowner(int t); void SetTownerGPtrs(BYTE *pData, BYTE **pAnim); diff --git a/Source/track.cpp b/Source/track.cpp index c8cc8bbee..c3bab984b 100644 --- a/Source/track.cpp +++ b/Source/track.cpp @@ -34,7 +34,7 @@ void track_repeat_walk(BOOL rep) sgbIsWalking = rep; if (rep) { - sgbIsScrolling = 0; + sgbIsScrolling = FALSE; sgdwLastWalk = GetTickCount() - 50; NetSendCmdLoc(TRUE, CMD_WALKXY, cursmx, cursmy); } else if (sgbIsScrolling) { diff --git a/Source/trigs.cpp b/Source/trigs.cpp index 0171b911b..af827651f 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -33,30 +33,34 @@ void InitTownTriggers() { int i; - trigs[0]._tx = 25; - trigs[0]._ty = 29; - trigs[0]._tmsg = WM_DIABNEXTLVL; + numtrigs = 0; + + trigs[numtrigs]._tx = 25; + trigs[numtrigs]._ty = 29; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; - numtrigs = 1; #ifndef SPAWN if (gbMaxPlayers == MAX_PLRS) { for (i = 0; i < sizeof(townwarps) / sizeof(townwarps[0]); i++) { townwarps[i] = TRUE; } - trigs[1]._tx = 49; - trigs[1]._ty = 21; - trigs[1]._tmsg = WM_DIABTOWNWARP; - trigs[1]._tlvl = 5; - trigs[2]._tx = 17; - trigs[2]._ty = 69; - trigs[2]._tmsg = WM_DIABTOWNWARP; - trigs[2]._tlvl = 9; - trigs[3]._tx = 41; - trigs[3]._ty = 80; - trigs[3]._tmsg = WM_DIABTOWNWARP; - trigs[3]._tlvl = 13; - numtrigs = 4; + trigs[numtrigs]._tx = 49; + trigs[numtrigs]._ty = 21; + trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; + trigs[numtrigs]._tlvl = 5; + numtrigs++; + trigs[numtrigs]._tx = 17; + trigs[numtrigs]._ty = 69; + trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; + trigs[numtrigs]._tlvl = 9; + numtrigs++; + trigs[numtrigs]._tx = 41; + trigs[numtrigs]._ty = 80; + trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; + trigs[numtrigs]._tlvl = 13; + numtrigs++; } else { #endif for (i = 0; i < MAX_PLRS - 1; i++) { @@ -64,11 +68,11 @@ void InitTownTriggers() } #ifndef SPAWN if (plr[myplr].pTownWarps & 1) { - trigs[1]._tx = 49; - trigs[1]._ty = 21; - trigs[1]._tmsg = WM_DIABTOWNWARP; - trigs[1]._tlvl = 5; - numtrigs = 2; + trigs[numtrigs]._tx = 49; + trigs[numtrigs]._ty = 21; + trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; + trigs[numtrigs]._tlvl = 5; + numtrigs++; townwarps[0] = TRUE; } if (plr[myplr].pTownWarps & 2) { diff --git a/defs.h b/defs.h index 6c5ea2cb6..0f67c867f 100644 --- a/defs.h +++ b/defs.h @@ -56,6 +56,8 @@ #define VOLUME_MIN -1600 #define VOLUME_MAX 0 +#define NUM_TOWNERS 16 + // todo: enums #define NUMLEVELS 17 #define SMITH_ITEMS 20