From 95d45d1c354ecf040eec7f39a039307788829cde Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 5 May 2019 20:45:08 +0200 Subject: [PATCH 01/37] Fix SpawnRock --- Source/items.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/items.cpp b/Source/items.cpp index 18b4cc63e..eb0e5d897 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2354,7 +2354,7 @@ void SpawnRock() item[i]._ix = xx; item[i]._iy = yy; dItem[xx][item[i]._iy] = i + 1; - GetItemAttrs(i, 7, currlevel); + GetItemAttrs(i, IDI_ROCK, currlevel); SetupItem(i); item[i]._iSelFlag = 2; item[i]._iPostDraw = 1; From c346435886ec69c9641148df33352424ce646576 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sat, 4 May 2019 21:12:52 -0500 Subject: [PATCH 02/37] test cd access --- Source/init.cpp | 55 +++++++++++++++++++++++-------------------------- Source/init.h | 2 +- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Source/init.cpp b/Source/init.cpp index a9288e8d1..eab9e576a 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -326,38 +326,35 @@ char *init_strip_trailing_slash(char *path) return result; } -int init_read_test_file(char *mpq_path, char *mpq_name, int flags, HANDLE *archive) +BOOL init_read_test_file(char *pszPath, char *pszArchive, int flags, HANDLE *phArchive) { - char *v4; // edi - DWORD v5; // eax - const char *v7; // ebx - const char *v8; // esi - char Buffer[MAX_PATH]; // [esp+Ch] [ebp-108h] - char *mpq_patha; // [esp+110h] [ebp-4h] - - v4 = mpq_name; - mpq_patha = mpq_path; - v5 = GetLogicalDriveStrings(sizeof(Buffer), Buffer); - if (!v5 || v5 > sizeof(Buffer)) - return 0; - while (*v4 == '\\') - ++v4; - v7 = Buffer; - if (!Buffer[0]) - return 0; - while (1) { - v8 = v7; - v7 += strlen(v7) + 1; - if (GetDriveType(v8) == DRIVE_CDROM) { - strcpy(mpq_patha, v8); - strcat(mpq_patha, v4); - if (SFileOpenArchive(mpq_patha, flags, 1, archive)) - break; + DWORD dwSize; + char *pszDrive, *pszRoot; + char szDrive[MAX_PATH]; + + dwSize = GetLogicalDriveStrings(sizeof(szDrive), szDrive); + if(dwSize == 0 || dwSize > sizeof(szDrive)) { + return FALSE; + } + + while(*pszArchive == '\\') { + pszArchive++; + } + + pszDrive = szDrive; + while(*pszDrive != '\0') { + pszRoot = pszDrive; + while(*pszDrive++ != '\0'); + if(GetDriveType(pszRoot) == DRIVE_CDROM) { + strcpy(pszPath, pszRoot); + strcat(pszPath, pszArchive); + if(SFileOpenArchive(pszPath, flags, 1, phArchive)) { + return TRUE; + } } - if (!*v7) - return 0; } - return 1; + + return FALSE; } void init_get_file_info() diff --git a/Source/init.h b/Source/init.h index cca31acf8..7b7a46ac9 100644 --- a/Source/init.h +++ b/Source/init.h @@ -25,7 +25,7 @@ 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); -int init_read_test_file(char *mpq_path, char *mpq_name, int flags, HANDLE *archive); +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); void init_activate_window(HWND hWnd, BOOL bActive); From b971d8a2cbffe12ad87782e5f54108a6523dbe09 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Sun, 5 May 2019 17:57:23 +0300 Subject: [PATCH 03/37] Make DrawLine bin exact by copying from its original source. --- Source/engine.cpp | 366 +++++++++++++++++++++------------------------- 1 file changed, 167 insertions(+), 199 deletions(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index c5c0a0499..3ee5341b8 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -2088,234 +2088,202 @@ void engine_draw_pixel(int sx, int sy) // 52B99C: using guessed type int gbNotInView; // 69CF0C: using guessed type int gpBufEnd; -/* - * Xiaolin Wu's anti-aliased line algorithm - */ +// Exact copy from https://github.com/erich666/GraphicsGems/blob/dad26f941e12c8bf1f96ea21c1c04cd2206ae7c9/gems/DoubleLine.c +// Except: +// * not in view checks +// * global variable instead of reverse flag +// * condition for pixels_left < 0 removed + +#define GG_SWAP(A, B) \ + { \ + (A) ^= (B); \ + (B) ^= (A); \ + (A) ^= (B); \ + } +#define GG_ABSOLUTE(I, J, K) (((I) - (J)) * ((K) = (((I) - (J)) < 0 ? -1 : 1))) + void DrawLine(int x0, int y0, int x1, int y1, BYTE col) { - int i, sx, sy, dx, dy, nx, ny, xlen, ylen, pixels, remain, xy_same, line_dir, mult_2, mult_4; + int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left; + int sign_x, sign_y, step, i; + int x1_, y1_; gbPixelCol = col; gbNotInView = FALSE; - if(x0 < 0 + 64 || x0 >= 640 + 64) { + if (x0 < 0 + 64 || x0 >= 640 + 64) { gbNotInView = TRUE; } - if(x1 < 0 + 64 || x1 >= 640 + 64) { + if (x1 < 0 + 64 || x1 >= 640 + 64) { gbNotInView = TRUE; } - if(y0 < 0 + 160 || y0 >= 352 + 160) { + if (y0 < 0 + 160 || y0 >= 352 + 160) { gbNotInView = TRUE; } - if(y1 < 0 + 160 || y1 >= 352 + 160) { + if (y1 < 0 + 160 || y1 >= 352 + 160) { gbNotInView = TRUE; } - if(x1 - x0 < 0) { - nx = -1; - } else { - nx = 1; - } - xlen = nx * (x1 - x0); - - if(y1 - y0 < 0) { - ny = -1; - } else { - ny = 1; - } - ylen = ny * (y1 - y0); - - if(ny == nx) { - xy_same = 1; - } else { - xy_same = -1; - } + dx = GG_ABSOLUTE(x1, x0, sign_x); + dy = GG_ABSOLUTE(y1, y0, sign_y); + /* decide increment sign by the slope sign */ + if (sign_x == sign_y) + step = 1; + else + step = -1; - if(ylen > xlen) { - x0 ^= y0 ^= x0 ^= y0; - x1 ^= y1 ^= x1 ^= y1; - xlen ^= ylen ^= xlen ^= ylen; + if (dy > dx) { /* chooses axis of greatest movement (make + * dx) */ + GG_SWAP(x0, y0); + GG_SWAP(x1, y1); + GG_SWAP(dx, dy); gbRotateMap = TRUE; - } else { + } else gbRotateMap = FALSE; - } - - if(x0 > x1) { - sx = x1; - sy = y1; - dx = x0; - dy = y0; + /* note error check for dx==0 should be included here */ + if (x0 > x1) { /* start from the smaller coordinate */ + x = x1; + y = y1; + x1_ = x0; + y1_ = y0; } else { - sx = x0; - sy = y0; - dx = x1; - dy = y1; + x = x0; + y = y0; + x1_ = x1; + y1_ = y1; } - pixels = (xlen - 1) / 4; - remain = (xlen - 1) % 4; - engine_draw_pixel(sx, sy); - engine_draw_pixel(dx, dy); - - line_dir = (ylen << 2) - xlen - xlen; - if(line_dir < 0) { - mult_2 = ylen << 1; - mult_4 = (mult_2 << 1) - xlen; - for(i = 0; i < pixels; i++) { - sx++; - dx--; - if(mult_4 < 0) { - engine_draw_pixel(sx, sy); - sx++; - engine_draw_pixel(sx, sy); - engine_draw_pixel(dx, dy); - dx--; - engine_draw_pixel(dx, dy); - mult_4 += mult_2 + mult_2; - } else if(mult_4 < mult_2) { - engine_draw_pixel(sx, sy); - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - engine_draw_pixel(dx, dy); - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - mult_4 += line_dir; + /* Note dx=n implies 0 - n or (dx+1) pixels to be set */ + /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */ + /* In fact (dx-1)/4 as 2 pixels are already plotted */ + xend = (dx - 1) / 4; + pixels_left = (dx - 1) % 4; /* number of pixels left over at the end */ + engine_draw_pixel(x, y); + engine_draw_pixel(x1_, y1_); /* plot first two points */ + incr2 = 4 * dy - 2 * dx; + if (incr2 < 0) { /* slope less than 1/2 */ + c = 2 * dy; + incr1 = 2 * c; + D = incr1 - dx; + + for (i = 0; i < xend; i++) { /* plotting loop */ + ++x; + --x1_; + if (D < 0) { + /* pattern 1 forwards */ + engine_draw_pixel(x, y); + engine_draw_pixel(++x, y); + /* pattern 1 backwards */ + engine_draw_pixel(x1_, y1_); + engine_draw_pixel(--x1_, y1_); + D += incr1; } else { - sy += xy_same; - engine_draw_pixel(sx, sy); - sx++; - engine_draw_pixel(sx, sy); - dy -= xy_same; - engine_draw_pixel(dx, dy); - dx--; - engine_draw_pixel(dx, dy); - mult_4 += line_dir; - } - } - if(remain != 0) { - if(mult_4 < 0) { - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dx--; - engine_draw_pixel(dx, dy); - } - } else if(mult_4 < mult_2) { - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dx--; - engine_draw_pixel(dx, dy); + if (D < c) { + /* pattern 2 forwards */ + engine_draw_pixel(x, y); + engine_draw_pixel(++x, y += step); + /* pattern 2 backwards */ + engine_draw_pixel(x1_, y1_); + engine_draw_pixel(--x1_, y1_ -= step); + } else { + /* pattern 3 forwards */ + engine_draw_pixel(x, y += step); + engine_draw_pixel(++x, y); + /* pattern 3 backwards */ + engine_draw_pixel(x1_, y1_ -= step); + engine_draw_pixel(--x1_, y1_); } + D += incr2; + } + } /* end for */ + + /* plot last pattern */ + if (pixels_left) { + if (D < 0) { + engine_draw_pixel(++x, y); /* pattern 1 */ + if (pixels_left > 1) + engine_draw_pixel(++x, y); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_); } else { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); + if (D < c) { + engine_draw_pixel(++x, y); /* pattern 2 */ + if (pixels_left > 1) + engine_draw_pixel(++x, y += step); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_); + } else { + /* pattern 3 */ + engine_draw_pixel(++x, y += step); + if (pixels_left > 1) + engine_draw_pixel(++x, y); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_ -= step); } } - } - } else { - mult_2 = (ylen - xlen) << 1; - mult_4 = (mult_2 << 1) + xlen; - for(i = 0; i < pixels; i++) { - sx++; - dx--; - if(mult_4 > 0) { - sy += xy_same; - engine_draw_pixel(sx, sy); - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - dy -= xy_same; - engine_draw_pixel(dx, dy); - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - mult_4 += mult_2 + mult_2; - } else if(mult_4 < mult_2) { - engine_draw_pixel(sx, sy); - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - engine_draw_pixel(dx, dy); - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - mult_4 += line_dir; + } /* end if pixels_left */ + } + /* end slope < 1/2 */ + else { /* slope greater than 1/2 */ + c = 2 * (dy - dx); + incr1 = 2 * c; + D = incr1 + dx; + for (i = 0; i < xend; i++) { + ++x; + --x1_; + if (D > 0) { + /* pattern 4 forwards */ + engine_draw_pixel(x, y += step); + engine_draw_pixel(++x, y += step); + /* pattern 4 backwards */ + engine_draw_pixel(x1_, y1_ -= step); + engine_draw_pixel(--x1_, y1_ -= step); + D += incr1; } else { - sy += xy_same; - engine_draw_pixel(sx, sy); - sx++; - engine_draw_pixel(sx, sy); - dy -= xy_same; - engine_draw_pixel(dx, dy); - dx--; - engine_draw_pixel(dx, dy); - mult_4 += line_dir; - } - } - if(remain != 0) { - if(mult_4 > 0) { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - } - } else if(mult_4 < mult_2) { - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dx--; - engine_draw_pixel(dx, dy); + if (D < c) { + /* pattern 2 forwards */ + engine_draw_pixel(x, y); + engine_draw_pixel(++x, y += step); + + /* pattern 2 backwards */ + engine_draw_pixel(x1_, y1_); + engine_draw_pixel(--x1_, y1_ -= step); + } else { + /* pattern 3 forwards */ + engine_draw_pixel(x, y += step); + engine_draw_pixel(++x, y); + /* pattern 3 backwards */ + engine_draw_pixel(x1_, y1_ -= step); + engine_draw_pixel(--x1_, y1_); } + D += incr2; + } + } /* end for */ + /* plot last pattern */ + if (pixels_left) { + if (D > 0) { + engine_draw_pixel(++x, y += step); /* pattern 4 */ + if (pixels_left > 1) + engine_draw_pixel(++x, y += step); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_ -= step); } else { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - if(mult_4 > mult_2) { - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - } else { - dx--; - engine_draw_pixel(dx, dy); + if (D < c) { + engine_draw_pixel(++x, y); /* pattern 2 */ + if (pixels_left > 1) + engine_draw_pixel(++x, y += step); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_); + } else { + /* pattern 3 */ + engine_draw_pixel(++x, y += step); + if (pixels_left > 1) + engine_draw_pixel(++x, y); + if (pixels_left > 2) { + if (D > c) /* step 3 */ + engine_draw_pixel(--x1_, y1_ -= step); + else /* step 2 */ + engine_draw_pixel(--x1_, y1_); } } } From 5f0fb73b8cff9af2d5375218d68d5ac79bf1ed6e Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Sun, 5 May 2019 20:30:32 +0300 Subject: [PATCH 04/37] Make mainmenu_create_hero bin exact (4 unused arguments added) --- Source/mainmenu.cpp | 4 ++-- Source/mainmenu.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/mainmenu.cpp b/Source/mainmenu.cpp index 17233a24f..5b7e43847 100644 --- a/Source/mainmenu.cpp +++ b/Source/mainmenu.cpp @@ -18,9 +18,9 @@ void mainmenu_refresh_music() } while (!menu_music_track_id || menu_music_track_id == 1); } -void __stdcall mainmenu_create_hero(char *name_1, char *name_2) +void __stdcall mainmenu_create_hero(int arg1, int arg2, int arg3, int arg4, char *name_1, char *name_2) { - if (UiValidPlayerName(name_1)) + if (UiValidPlayerName(name_2)) pfile_create_save_file(name_1, name_2); } diff --git a/Source/mainmenu.h b/Source/mainmenu.h index 8e7f9257a..a9155438e 100644 --- a/Source/mainmenu.h +++ b/Source/mainmenu.h @@ -5,7 +5,7 @@ extern char gszHero[16]; void mainmenu_refresh_music(); -void __stdcall mainmenu_create_hero(char *name_1, char *name_2); +void __stdcall mainmenu_create_hero(int arg1, int arg2, int arg3, int arg4, char *name_1, char *name_2); int __stdcall mainmenu_select_hero_dialog( const _SNETPROGRAMDATA *client_info, const _SNETPLAYERDATA *user_info, From 43d63110f141c83e36a2f0c5b6e3790e5e9067cb Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Mon, 6 May 2019 00:47:48 +0300 Subject: [PATCH 05/37] Make AddTorturedBody bin exact. --- Source/objects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index e639a2435..8d50d9a59 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1267,8 +1267,8 @@ void AddWeaponRack(int i) void AddTorturedBody(int i) { object[i]._oRndSeed = GetRndSeed(); - object[i]._oPreFlag = TRUE; object[i]._oAnimFrame = random(0, 4) + 1; + object[i]._oPreFlag = TRUE; } void GetRndObjLoc(int randarea, int *xx, int *yy) From 94632eb2a6c37a5803a853ebaf844c8a68577fb3 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Mon, 6 May 2019 00:59:11 +0300 Subject: [PATCH 06/37] Make Obj_Circle bin exact. --- Source/objects.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 8d50d9a59..4e3745b84 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1510,12 +1510,17 @@ void Obj_Circle(int i) object[i]._oAnimFrame = 2; if (object[i]._otype == OBJ_MCIRCLE2) object[i]._oAnimFrame = 4; - if (ox == 45 && oy == 47) { - object[i]._oVar6 = 2; - return; - } else if (object[i]._ox == 26 && object[i]._oy == 46) { + if (ox == 45) { + if (oy == 47) { + object[i]._oVar6 = 2; + return; + } + } + else { + if (object[i]._ox == 26 && object[i]._oy == 46) { object[i]._oVar6 = 1; return; + } } object[i]._oVar6 = 0; if (ox == 35 && object[i]._oy == 36 && object[i]._oVar5 == 3) { From 187bf5844edcaaf7551915b506cd57cd2d0f8d14 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Mon, 6 May 2019 01:03:16 +0300 Subject: [PATCH 07/37] Make ActivateTrapLine bin exact. --- Source/objects.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 4e3745b84..1c0bd0c59 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1577,9 +1577,9 @@ void ActivateTrapLine(int ttype, int tid) { int i, oi; - for (i = ttype; i < nobjects; i++) { + for (i = 0; i < nobjects; i++) { oi = objectactive[i]; - if (object[oi]._otype == i && object[oi]._oVar1 == tid) { + if (object[oi]._otype == ttype && object[oi]._oVar1 == tid) { object[oi]._oVar4 = 1; object[oi]._oAnimFlag = 1; object[oi]._oAnimDelay = 1; From 33e9005239097d890f3e4a24a4db559293dd9ab0 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Mon, 6 May 2019 01:06:43 +0300 Subject: [PATCH 08/37] Make OperateL{1-3}Door bin exact. --- Source/objects.cpp | 24 ++++++++++++------------ Source/objects.h | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 1c0bd0c59..3fa61fbe5 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2385,7 +2385,7 @@ void ObjChangeMapResync(int x1, int y1, int x2, int y2) } } -void OperateL1Door(int pnum, int i, unsigned char sendflag) +void OperateL1Door(int pnum, int i, BOOL sendflag) { int dpx, dpy; @@ -2745,7 +2745,7 @@ void OperateSarc(int pnum, int i, BOOL sendmsg) } } -void OperateL2Door(int pnum, int i, unsigned char sendflag) +void OperateL2Door(int pnum, int i, BOOL sendflag) { int dpx, dpy; @@ -2757,7 +2757,7 @@ void OperateL2Door(int pnum, int i, unsigned char sendflag) OperateL2RDoor(pnum, i, sendflag); } -void OperateL3Door(int pnum, int i, unsigned char sendflag) +void OperateL3Door(int pnum, int i, BOOL sendflag) { int dpx, dpy; @@ -3767,37 +3767,37 @@ void OperateObject(int pnum, int i, BOOL TeleFlag) case OBJ_L1RDOOR: if (TeleFlag) { if (object[i]._otype == OBJ_L1LDOOR) - OperateL1LDoor(pnum, i, 1); + OperateL1LDoor(pnum, i, TRUE); if (object[i]._otype == OBJ_L1RDOOR) - OperateL1RDoor(pnum, i, 1); + OperateL1RDoor(pnum, i, TRUE); break; } if (pnum == myplr) - OperateL1Door(pnum, i, 1); + OperateL1Door(pnum, i, TRUE); break; case OBJ_L2LDOOR: case OBJ_L2RDOOR: if (TeleFlag) { if (object[i]._otype == OBJ_L2LDOOR) - OperateL2LDoor(pnum, i, 1); + OperateL2LDoor(pnum, i, TRUE); if (object[i]._otype == OBJ_L2RDOOR) - OperateL2RDoor(pnum, i, 1); + OperateL2RDoor(pnum, i, TRUE); break; } if (pnum == myplr) - OperateL2Door(pnum, i, 1); + OperateL2Door(pnum, i, TRUE); break; case OBJ_L3LDOOR: case OBJ_L3RDOOR: if (TeleFlag) { if (object[i]._otype == OBJ_L3LDOOR) - OperateL3LDoor(pnum, i, 1); + OperateL3LDoor(pnum, i, TRUE); if (object[i]._otype == OBJ_L3RDOOR) - OperateL3RDoor(pnum, i, 1); + OperateL3RDoor(pnum, i, TRUE); break; } if (pnum == myplr) - OperateL3Door(pnum, i, 1); + OperateL3Door(pnum, i, TRUE); break; case OBJ_LEVER: case OBJ_SWITCHSKL: diff --git a/Source/objects.h b/Source/objects.h index 0c8efcab6..2864a5a17 100644 --- a/Source/objects.h +++ b/Source/objects.h @@ -105,7 +105,7 @@ void OperateL3LDoor(int pnum, int oi, BOOL sendflag); void MonstCheckDoors(int m); void ObjChangeMap(int x1, int y1, int x2, int y2); void ObjChangeMapResync(int x1, int y1, int x2, int y2); -void OperateL1Door(int pnum, int i, unsigned char sendflag); +void OperateL1Door(int pnum, int i, BOOL sendflag); void OperateLever(int pnum, int i); void OperateBook(int pnum, int i); void OperateBookLever(int pnum, int i); @@ -116,8 +116,8 @@ void OperateInnSignChest(int pnum, int i); void OperateSlainHero(int pnum, int i, BOOL sendmsg); void OperateTrapLvr(int i); void OperateSarc(int pnum, int i, BOOL sendmsg); -void OperateL2Door(int pnum, int i, unsigned char sendflag); -void OperateL3Door(int pnum, int i, unsigned char sendflag); +void OperateL2Door(int pnum, int i, BOOL sendflag); +void OperateL3Door(int pnum, int i, BOOL sendflag); void OperatePedistal(int pnum, int i); void TryDisarm(int pnum, int i); int ItemMiscIdIdx(int imiscid); From a87f1450e750f4b0cf08510e68be970212fb237a Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Mon, 6 May 2019 02:32:19 +0300 Subject: [PATCH 09/37] Add algorithm description comment for DrawLine. --- Source/engine.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/engine.cpp b/Source/engine.cpp index 3ee5341b8..065c9ea4b 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -2094,6 +2094,12 @@ void engine_draw_pixel(int sx, int sy) // * global variable instead of reverse flag // * condition for pixels_left < 0 removed +/* +Symmetric Double Step Line Algorithm +by Brian Wyvill +from "Graphics Gems", Academic Press, 1990 +*/ + #define GG_SWAP(A, B) \ { \ (A) ^= (B); \ From 3b9ff3cc33bc00aea3bf4077b46bac4e618c4f2b Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sun, 5 May 2019 23:31:15 -0500 Subject: [PATCH 10/37] MakeLightTable --- Source/lighting.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/lighting.cpp b/Source/lighting.cpp index a23ff8e81..09747aeb2 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -914,12 +914,12 @@ void MakeLightTable() *tbl++ = 0; } - for (i = 0; i < 16; i++) { - for (j = 0; j < 128; j++) { - if (j > (i + 1) * 8) { /* check */ - lightradius[i][j] = 15; + for (k = 0; k < 16; k++) { + for (l = 0; l < 128; l++) { + if (l > (k + 1) * 8) { + lightradius[k][l] = 15; } else { - lightradius[i][j] = j * 15.0 / ((i + 1) * 8.0) + 0.5; + lightradius[k][l] = l * 15.0 / ((k + 1) * 8.0) + 0.5; } } } From 02acf7629bc4db65fc7559e34bf6de55546c1de7 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Tue, 7 May 2019 00:48:20 +0300 Subject: [PATCH 11/37] Make ResyncQuests bin exact. --- Source/quests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/quests.cpp b/Source/quests.cpp index 098ad54d6..c1dd8d2f0 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -610,7 +610,7 @@ void ResyncQuests() else LoadPalette("Levels\\L3Data\\L3pfoul.pal"); - for (i = 0; i < 32; i++) + for (i = 0; i <= 32; i++) palette_update_quest_palette(i); } From 47aee25195963b38f07a35ddcd9e753c88a39b03 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Tue, 7 May 2019 00:53:57 +0300 Subject: [PATCH 12/37] Make Do_Death bin exact. --- Source/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/player.cpp b/Source/player.cpp index 208050762..8e6f0aa14 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -2923,7 +2923,7 @@ BOOL PM_DoDeath(int pnum) if (plr[pnum]._pVar8 >= 2 * plr[pnum]._pDFrames) { if (deathdelay > 1 && pnum == myplr) { deathdelay--; - if (deathdelay) { + if (deathdelay == 1) { deathflag = TRUE; if (gbMaxPlayers == 1) { gamemenu_previous(); From 41767ae5efc8b951386d59dbdb6891c0453fc075 Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 6 May 2019 04:56:44 +0200 Subject: [PATCH 13/37] gmenu_draw bin exact --- Source/gmenu.cpp | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 5495c65e2..3055db853 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -5,8 +5,8 @@ BOOLEAN mouseNavigation; // weak void *PentSpin_cel; TMenuItem *sgpCurrItem; void *BigTGold_cel; -int dword_634474; // weak -char byte_634478; // weak +int PentSpin_tick; // weak +char PentSpin_frame; // weak void(*dword_63447C)(TMenuItem *); TMenuItem *sgpCurrentMenu; // idb void *option_cel; @@ -72,7 +72,7 @@ void FreeGMenu() void gmenu_init_menu() { - byte_634478 = 1; + PentSpin_frame = 1; sgpCurrentMenu = 0; sgpCurrItem = 0; dword_63447C = 0; @@ -85,7 +85,7 @@ void gmenu_init_menu() optbar_cel = LoadFileInMem("Data\\optbar.CEL", 0); } // 634464: using guessed type char mouseNavigation; -// 634478: using guessed type char byte_634478; +// 634478: using guessed type char PentSpin_frame; // 63448C: using guessed type int sgCurrentMenuIdx; BOOL gmenu_exception() @@ -159,29 +159,33 @@ void gmenu_up_down(BOOL isDown) void gmenu_draw() { - int v0; // edi - TMenuItem *i; // esi - DWORD v2; // eax + int y; + TMenuItem *i; + DWORD ticks; if (sgpCurrentMenu) { if (dword_63447C) dword_63447C(sgpCurrentMenu); CelDecodeOnly(236, 262, (BYTE *)sgpLogo, 1, 296); - v0 = 320; - for (i = sgpCurrentMenu; i->fnMenu; v0 += 45) { - gmenu_draw_menu_item(i, v0); - ++i; + y = 320; + i = sgpCurrentMenu; + if (sgpCurrentMenu->fnMenu) { + while (i->fnMenu) { + gmenu_draw_menu_item(i, y); + i++; + y += 45; + } } - v2 = GetTickCount(); - if ((signed int)(v2 - dword_634474) > 25) { - if (++byte_634478 == 9) - byte_634478 = 1; - dword_634474 = v2; + + ticks = GetTickCount(); + if ((signed int)(ticks - PentSpin_tick) > 25) { + PentSpin_frame++; + if (PentSpin_frame == 9) + PentSpin_frame = 1; + PentSpin_tick = ticks; } } } -// 634474: using guessed type int dword_634474; -// 634478: using guessed type char byte_634478; void gmenu_draw_menu_item(TMenuItem *pItem, int a2) { @@ -224,11 +228,11 @@ void gmenu_draw_menu_item(TMenuItem *pItem, int a2) gmenu_print_text(384 - (v5 >> 1), v2, v3->pszStr); if (v3 == sgpCurrItem) { v13 = v2 + 1; - CelDecodeOnly(v11 - 54, v13, (BYTE *)PentSpin_cel, (unsigned char)byte_634478, 48); - CelDecodeOnly(v11 + v5 + 4, v13, (BYTE *)PentSpin_cel, (unsigned char)byte_634478, 48); + CelDecodeOnly(v11 - 54, v13, (BYTE *)PentSpin_cel, (unsigned char)PentSpin_frame, 48); + CelDecodeOnly(v11 + v5 + 4, v13, (BYTE *)PentSpin_cel, (unsigned char)PentSpin_frame, 48); } } -// 634478: using guessed type char byte_634478; +// 634478: using guessed type char PentSpin_frame; // 69BEF8: using guessed type int light_table_index; void gmenu_clear_buffer(int x, int y, int width, int height) From 6733cb1b2e98526ea02b48677ffcb8b3c12d1167 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 6 May 2019 23:06:29 +0100 Subject: [PATCH 14/37] Update Source/gmenu.cpp --- Source/gmenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 3055db853..c0182fe43 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -178,7 +178,7 @@ void gmenu_draw() } ticks = GetTickCount(); - if ((signed int)(ticks - PentSpin_tick) > 25) { + if ((int)(ticks - PentSpin_tick) > 25) { PentSpin_frame++; if (PentSpin_frame == 9) PentSpin_frame = 1; From 82e8d6ed60597591ade71969f09c385b7c810080 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Thu, 2 May 2019 22:39:43 -0500 Subject: [PATCH 15/37] Fix trigflag, trigs.cpp bin exact --- Source/control.cpp | 4 +- Source/cursor.cpp | 6 +- Source/missiles.cpp | 2 +- Source/monster.cpp | 2 +- Source/quests.cpp | 8 +- Source/themes.cpp | 2 +- Source/trigs.cpp | 342 +++++++++++++++++++++----------------------- Source/trigs.h | 10 +- 8 files changed, 178 insertions(+), 198 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index f4bb13bf2..c2e4fd901 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1648,9 +1648,9 @@ void DrawInfoBox() char *v10; // ebx DrawPanelBox(177, 62, 288, 60, 241, 558); - v0 = trigflag_3; + v0 = trigflag; v1 = spselflag; - if (!panelflag && !trigflag_3 && pcursinvitem == -1) { + if (!panelflag && !trigflag && pcursinvitem == -1) { if (spselflag) { LABEL_32: infoclr = COL_WHITE; diff --git a/Source/cursor.cpp b/Source/cursor.cpp index c655e85a4..f88b83507 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -127,7 +127,7 @@ void CheckTown() || cursmx == missile[mx]._mix - 2 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix - 1 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix && cursmy == missile[mx]._miy) { - trigflag_3 = 1; + trigflag = 1; ClearPanel(); strcpy(infostr, "Town Portal"); sprintf(tempstr, "from %s", plr[missile[mx]._misource]._pName); @@ -153,7 +153,7 @@ void CheckRportal() || cursmx == missile[mx]._mix - 2 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix - 1 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix && cursmy == missile[mx]._miy) { - trigflag_3 = 1; + trigflag = 1; ClearPanel(); strcpy(infostr, "Portal to"); if (!setlevel) @@ -261,7 +261,7 @@ void CheckCursMove() pcursplr = -1; uitemflag = 0; panelflag = 0; - trigflag_3 = 0; + trigflag = 0; if(plr[myplr]._pInvincible) { return; diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 8c97f4da0..43d9cf733 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1748,7 +1748,7 @@ BOOL CheckIfTrig(int x, int y) { int i; - for (i = 0; i < trigflag_4; i++) { + for (i = 0; i < numtrigs; i++) { if ((x == trigs[i]._tx && y == trigs[i]._ty) || (abs(trigs[i]._tx - x) < 2 && abs(trigs[i]._ty - y) < 2)) return TRUE; } diff --git a/Source/monster.cpp b/Source/monster.cpp index fc037db61..b07b6b827 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -956,7 +956,7 @@ void InitMonsters() if (!setlevel && currlevel == 16) LoadDiabMonsts(); } - nt = trigflag_4; + nt = numtrigs; if (currlevel == 15) nt = 1; for (i = 0; i < nt; i++) { diff --git a/Source/quests.cpp b/Source/quests.cpp index c1dd8d2f0..755b39e00 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -300,10 +300,10 @@ void CheckQuestKill(int m, BOOL sendmsg) for (j = 0; j < 112; j++) { for (i = 0; i < 112; i++) { if (dPiece[i][j] == 370) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = 1026; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = 1026; + numtrigs++; } } } diff --git a/Source/themes.cpp b/Source/themes.cpp index 52f8117e4..9f30017da 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -349,7 +349,7 @@ BOOL CheckThemeRoom(int tv) { int i, j, tarea; - for (i = 0; i < trigflag_4; i++) { + for (i = 0; i < numtrigs; i++) { if (dTransVal[trigs[i]._tx][trigs[i]._ty] == tv) return FALSE; } diff --git a/Source/trigs.cpp b/Source/trigs.cpp index 658197caa..e4634bc63 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -1,10 +1,8 @@ #include "diablo.h" -int trigflag_0; -int trigflag_1; -int trigflag_2; -int trigflag_3; -int trigflag_4; +BOOL townwarps[3]; +BOOL trigflag; +int numtrigs; TriggerStruct trigs[MAXTRIGGERS]; int TWarpFrom; // weak @@ -89,25 +87,25 @@ int L4PentaList[33] = { void InitNoTriggers() { - trigflag_4 = 0; - trigflag_3 = 0; + numtrigs = 0; + trigflag = 0; } void InitTownTriggers() { - char v0; // bl - int v1; // eax - int v2; // eax + int i; trigs[0]._tx = 25; trigs[0]._ty = 29; trigs[0]._tmsg = WM_DIABNEXTLVL; - trigflag_4 = 1; - if (gbMaxPlayers == 4) { + + numtrigs = 1; + + if(gbMaxPlayers == 4) { + for(i = 0; i < 3; i++) { + townwarps[i] = TRUE; + } trigs[1]._tx = 49; - trigflag_0 = 1; - trigflag_1 = 1; - trigflag_2 = 1; trigs[1]._ty = 21; trigs[1]._tmsg = WM_DIABTOWNWARP; trigs[1]._tlvl = 5; @@ -119,38 +117,38 @@ void InitTownTriggers() trigs[3]._ty = 80; trigs[3]._tmsg = WM_DIABTOWNWARP; trigs[3]._tlvl = 13; - trigflag_4 = 4; + numtrigs = 4; } else { - trigflag_0 = 0; - trigflag_1 = 0; - trigflag_2 = 0; - v0 = plr[myplr].pTownWarps; - if (v0 & 1) { + for(i = 0; i < 3; i++) { + townwarps[i] = FALSE; + } + if(plr[myplr].pTownWarps & 1) { trigs[1]._tx = 49; trigs[1]._ty = 21; trigs[1]._tmsg = WM_DIABTOWNWARP; trigs[1]._tlvl = 5; - trigflag_4 = 2; - trigflag_0 = 1; - } - if (v0 & 2) { - trigflag_1 = 1; - v1 = trigflag_4++; - trigs[v1]._tx = 17; - trigs[v1]._ty = 69; - trigs[v1]._tmsg = WM_DIABTOWNWARP; - trigs[v1]._tlvl = 9; - } - if (v0 & 4) { - trigflag_2 = 1; - v2 = trigflag_4++; - trigs[v2]._tx = 41; - trigs[v2]._ty = 80; - trigs[v2]._tmsg = WM_DIABTOWNWARP; - trigs[v2]._tlvl = 13; + numtrigs = 2; + townwarps[0] = TRUE; + } + if(plr[myplr].pTownWarps & 2) { + townwarps[1] = TRUE; + trigs[numtrigs]._tx = 17; + trigs[numtrigs]._ty = 69; + trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; + trigs[numtrigs]._tlvl = 9; + numtrigs++; + } + if(plr[myplr].pTownWarps & 4) { + townwarps[2] = TRUE; + trigs[numtrigs]._tx = 41; + trigs[numtrigs]._ty = 80; + trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; + trigs[numtrigs]._tlvl = 13; + numtrigs++; } } - trigflag_3 = 0; + + trigflag = FALSE; } // 679660: using guessed type char gbMaxPlayers; @@ -158,120 +156,120 @@ void InitL1Triggers() { int j, i; - trigflag_4 = 0; + numtrigs = 0; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 129) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABPREVLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABPREVLVL; + numtrigs++; } if (dPiece[i][j] == 115) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; } } } - trigflag_3 = 0; + trigflag = 0; } void InitL2Triggers() { int i, j; - trigflag_4 = 0; + numtrigs = 0; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 267 && (i != quests[QTYPE_BONE]._qtx || j != quests[QTYPE_BONE]._qty)) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABPREVLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABPREVLVL; + numtrigs++; } if (dPiece[i][j] == 559) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABTWARPUP; - trigs[trigflag_4]._tlvl = 0; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABTWARPUP; + trigs[numtrigs]._tlvl = 0; + numtrigs++; } if (dPiece[i][j] == 271) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; } } } - trigflag_3 = 0; + trigflag = 0; } void InitL3Triggers() { int i, j; - trigflag_4 = 0; + numtrigs = 0; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 171) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABPREVLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABPREVLVL; + numtrigs++; } if (dPiece[i][j] == 168) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4] ._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs] ._tmsg = WM_DIABNEXTLVL; + numtrigs++; } if (dPiece[i][j] == 549) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABTWARPUP; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABTWARPUP; + numtrigs++; } } } - trigflag_3 = 0; + trigflag = 0; } void InitL4Triggers() { int i, j; - trigflag_4 = 0; + numtrigs = 0; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 83) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABPREVLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABPREVLVL; + numtrigs++; } if (dPiece[i][j] == 422) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABTWARPUP; - trigs[trigflag_4]._tlvl = 0; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABTWARPUP; + trigs[numtrigs]._tlvl = 0; + numtrigs++; } if (dPiece[i][j] == 120) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; } } } @@ -279,20 +277,20 @@ void InitL4Triggers() for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 370 && quests[QTYPE_VB]._qactive == 3) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; } } } - trigflag_3 = 0; + trigflag = 0; } void InitSKingTriggers() { - trigflag_3 = 0; - trigflag_4 = 1; + trigflag = 0; + numtrigs = 1; trigs[0]._tx = 82; trigs[0]._ty = 42; trigs[0]._tmsg = WM_DIABRTNLVL; @@ -300,8 +298,8 @@ void InitSKingTriggers() void InitSChambTriggers() { - trigflag_3 = 0; - trigflag_4 = 1; + trigflag = 0; + numtrigs = 1; trigs[0]._tx = 70; trigs[0]._ty = 39; trigs[0]._tmsg = WM_DIABRTNLVL; @@ -309,8 +307,8 @@ void InitSChambTriggers() void InitPWaterTriggers() { - trigflag_3 = 0; - trigflag_4 = 1; + trigflag = 0; + numtrigs = 1; trigs[0]._tx = 30; trigs[0]._ty = 83; trigs[0]._tmsg = WM_DIABRTNLVL; @@ -318,8 +316,8 @@ void InitPWaterTriggers() void InitVPTriggers() { - trigflag_3 = 0; - trigflag_4 = 1; + trigflag = 0; + numtrigs = 1; trigs[0]._tx = 35; trigs[0]._ty = 32; trigs[0]._tmsg = WM_DIABRTNLVL; @@ -338,7 +336,7 @@ BOOL ForceTownTrig() } } - if (trigflag_0) { + if (townwarps[0]) { for (j = 0; TownWarp1List[j] != -1; j++) { if (dPiece[cursmx][cursmy] == TownWarp1List[j]) { strcpy(infostr, "Down to catacombs"); @@ -349,7 +347,7 @@ BOOL ForceTownTrig() } } - if (trigflag_1) { + if (townwarps[1]) { for (k = 1199; k <= 1220; k++) { if (dPiece[cursmx][cursmy] == k) { strcpy(infostr, "Down to caves"); @@ -360,7 +358,7 @@ BOOL ForceTownTrig() } } - if (trigflag_2) { + if (townwarps[2]) { for (l = 1240; l <= 1254; l++) { if (dPiece[cursmx][cursmy] == l) { strcpy(infostr, "Down to hell"); @@ -384,7 +382,7 @@ BOOL ForceL1Trig() sprintf(infostr, "Up to level %i", currlevel - 1); else strcpy(infostr, "Up to town"); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABPREVLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -397,7 +395,7 @@ BOOL ForceL1Trig() for (i = 0; L1DownList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L1DownList[i]) { sprintf(infostr, "Down to level %i", currlevel + 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -416,7 +414,7 @@ BOOL ForceL2Trig() for (i = 0; L2UpList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L2UpList[i]) { - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABPREVLVL) { dx = abs(trigs[j]._tx - cursmx); dy = abs(trigs[j]._ty - cursmy); @@ -434,7 +432,7 @@ BOOL ForceL2Trig() for (i = 0; L2DownList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L2DownList[i]) { sprintf(infostr, "Down to level %i", currlevel + 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -447,7 +445,7 @@ BOOL ForceL2Trig() if (currlevel == 5) { for (i = 0; L2TWarpUpList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L2TWarpUpList[i]) { - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABTWARPUP) { dx = abs(trigs[j]._tx - cursmx); dy = abs(trigs[j]._ty - cursmy); @@ -473,7 +471,7 @@ BOOL ForceL3Trig() for (i = 0; L3UpList[i] != -1; ++i) { if (dPiece[cursmx][cursmy] == L3UpList[i]) { sprintf(infostr, "Up to level %i", currlevel - 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABPREVLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -486,7 +484,7 @@ BOOL ForceL3Trig() for (i = 0; L3DownList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L3DownList[i] || dPiece[cursmx + 1][cursmy] == L3DownList[i] || dPiece[cursmx + 2][cursmy] == L3DownList[i]) { sprintf(infostr, "Down to level %i", currlevel + 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -499,7 +497,7 @@ BOOL ForceL3Trig() if (currlevel == 9) { for (i = 0; L3TWarpUpList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L3TWarpUpList[i]) { - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABTWARPUP) { dx = abs(trigs[j]._tx - cursmx); dy = abs(trigs[j]._ty - cursmy); @@ -525,7 +523,7 @@ BOOL ForceL4Trig() for (i = 0; L4UpList[i] != -1; ++i) { if (dPiece[cursmx][cursmy] == L4UpList[i]) { sprintf(infostr, "Up to level %i", currlevel - 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABPREVLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -538,7 +536,7 @@ BOOL ForceL4Trig() for (i = 0; L4DownList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L4DownList[i]) { sprintf(infostr, "Down to level %i", currlevel + 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -551,7 +549,7 @@ BOOL ForceL4Trig() if (currlevel == 13) { for (i = 0; L4TWarpUpList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L4TWarpUpList[i]) { - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABTWARPUP) { dx = abs(trigs[j]._tx - cursmx); dy = abs(trigs[j]._ty - cursmy); @@ -571,7 +569,7 @@ BOOL ForceL4Trig() for (i = 0; L4PentaList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L4PentaList[i]) { strcpy(infostr, "Down to Diablo"); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -589,7 +587,7 @@ void Freeupstairs() { int i, yy, xx, tx, ty; - for (i = 0; i < trigflag_4; i++) { + for (i = 0; i < numtrigs; i++) { tx = trigs[i]._tx; ty = trigs[i]._ty; @@ -654,63 +652,49 @@ BOOL ForcePWaterTrig() void CheckTrigForce() { - int v0; // eax - int v1; // eax - - trigflag_3 = 0; - if (MouseY <= 351) { - if (setlevel) { - switch (setlvlnum) { - case SL_SKELKING: - v1 = ForceSKingTrig(); - break; - case SL_BONECHAMB: - v1 = ForceSChambTrig(); - break; - case SL_POISONWATER: - v1 = ForcePWaterTrig(); - break; - default: - return; - } - goto LABEL_23; - } - if (leveltype) { - switch (leveltype) { - case DTYPE_CATHEDRAL: - v0 = ForceL1Trig(); - break; - case DTYPE_CATACOMBS: - v0 = ForceL2Trig(); - break; - case DTYPE_CAVES: - v0 = ForceL3Trig(); - break; - case DTYPE_HELL: - v0 = ForceL4Trig(); - break; - default: - LABEL_14: - if (leveltype == DTYPE_TOWN) - goto LABEL_24; - if (trigflag_3) { - LABEL_25: - ClearPanel(); - return; - } - v1 = ForceQuests(); - LABEL_23: - trigflag_3 = v1; - LABEL_24: - if (!trigflag_3) - return; - goto LABEL_25; - } - } else { - v0 = ForceTownTrig(); + trigflag = FALSE; + + if(MouseY > 352 - 1) { + return; + } + + if(!setlevel) { + switch(leveltype) { + case DTYPE_TOWN: + trigflag = ForceTownTrig(); + break; + case DTYPE_CATHEDRAL: + trigflag = ForceL1Trig(); + break; + case DTYPE_CATACOMBS: + trigflag = ForceL2Trig(); + break; + case DTYPE_CAVES: + trigflag = ForceL3Trig(); + break; + case DTYPE_HELL: + trigflag = ForceL4Trig(); + break; + } + if(leveltype != DTYPE_TOWN && !trigflag) { + trigflag = ForceQuests(); } - trigflag_3 = v0; - goto LABEL_14; + } else { + switch(setlvlnum) { + case SL_SKELKING: + trigflag = ForceSKingTrig(); + break; + case SL_BONECHAMB: + trigflag = ForceSChambTrig(); + break; + case SL_POISONWATER: + trigflag = ForcePWaterTrig(); + break; + } + } + + if(trigflag) { + ClearPanel(); } } // 5CF31D: using guessed type char setlevel; @@ -724,7 +708,7 @@ void CheckTriggers() if (plr[myplr]._pmode) return; - for (i = 0; i < trigflag_4; i++) { + for (i = 0; i < numtrigs; i++) { if (plr[myplr].WorldX != trigs[i]._tx || plr[myplr].WorldY != trigs[i]._ty) { continue; } diff --git a/Source/trigs.h b/Source/trigs.h index 5012da61a..7fe07eac5 100644 --- a/Source/trigs.h +++ b/Source/trigs.h @@ -2,13 +2,9 @@ #ifndef __TRIGS_H__ #define __TRIGS_H__ -// The trigflag variables (0-4) here were split up from the trigflag array. -// Complete diff is part of PR #947 on Github. -extern int trigflag_0; -extern int trigflag_1; -extern int trigflag_2; -extern int trigflag_3; -extern int trigflag_4; +extern BOOL townwarps[3]; +extern BOOL trigflag; +extern int numtrigs; extern TriggerStruct trigs[MAXTRIGGERS]; extern int TWarpFrom; // weak From a3e3cd4c23de897bf26ac8b748aa5e92ae2f1301 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 5 May 2019 19:15:05 +0200 Subject: [PATCH 16/37] Clean up ADD_PlrStringXY --- Source/control.cpp | 85 ++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 52 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index c2e4fd901..ba6a9d838 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1798,8 +1798,7 @@ void PrintGameStr(int x, int y, char *str, int color) int off; off = PitchTbl[y + 160] + x + 64; while (*str) { - c = gbFontTransTbl[(BYTE)*str]; - str++; + c = gbFontTransTbl[(BYTE)*str++]; c = fontframe[c]; if (c) CPrintString(off, c, color); @@ -2034,47 +2033,31 @@ void DrawChr() void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col) { - int v5; // eax - char *v6; // edx - unsigned char v7; // al - int v8; // esi - int v9; // edi - int v10; // ecx - unsigned char v11; // bl - unsigned char v12; // al - int v13; // ebx - int widtha; // [esp+Ch] [ebp-4h] - int widthb; // [esp+Ch] [ebp-4h] + BYTE c; + char *tmp; + int nOffset, screen_x, line, widthOffset; - v5 = PitchTbl[y + 160]; - v6 = pszStr; - widtha = v5 + x + 64; - v7 = *pszStr; - v8 = width - x + 1; - v9 = 0; - v10 = 0; - if (*pszStr) { - v11 = *pszStr; - do { - ++v6; - v10 += fontkern[fontframe[gbFontTransTbl[v11]]] + 1; - v11 = *v6; - } while (*v6); - } - if (v10 < v8) - v9 = (v8 - v10) >> 1; - widthb = v9 + widtha; - while (v7) { - ++pszStr; - v12 = fontframe[gbFontTransTbl[v7]]; - v13 = v12; - v9 += fontkern[v12] + 1; - if (v12) { - if (v9 < v8) - CPrintString(widthb, v12, col); + nOffset = x + PitchTbl[y + 160] + 64; + widthOffset = width - x + 1; + line = 0; + screen_x = 0; + tmp = pszStr; + while (*tmp) { + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + 1; + } + if (screen_x < widthOffset) + line = (widthOffset - screen_x) >> 1; + nOffset += line; + while (*pszStr) { + c = gbFontTransTbl[(BYTE)*pszStr++]; + c = fontframe[c]; + line += fontkern[c] + 1; + if (c) { + if (line < widthOffset) + CPrintString(nOffset, c, col); } - widthb += fontkern[v13] + 1; - v7 = *pszStr; + nOffset += fontkern[c] + 1; } } @@ -2438,7 +2421,7 @@ void DrawSpellBook() void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col) { - BYTE nCel; + BYTE c; char *tmp; int screen_x, line, width; @@ -2448,24 +2431,22 @@ void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col) screen_x = 0; tmp = pszStr; while (*tmp) { - nCel = gbFontTransTbl[(BYTE)*tmp]; - tmp++; - screen_x += fontkern[fontframe[nCel]] + 1; + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + 1; } if (screen_x < 222) line = (222 - screen_x) >> 1; width += line; } while (*pszStr) { - nCel = gbFontTransTbl[(BYTE)*pszStr]; - pszStr++; - nCel = fontframe[nCel]; - line += fontkern[nCel] + 1; - if (nCel) { + c = gbFontTransTbl[(BYTE)*pszStr++]; + c = fontframe[c]; + line += fontkern[c] + 1; + if (c) { if (line <= 222) - CPrintString(width, nCel, col); + CPrintString(width, c, col); } - width += fontkern[nCel] + 1; + width += fontkern[c] + 1; } } From 7a6609ad8ad1a376069239b819e051b390e5880c Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 5 May 2019 19:23:03 +0200 Subject: [PATCH 17/37] Clean up MY_PlrStringXY --- Source/control.cpp | 67 +++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index ba6a9d838..aedcb7b5c 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -2031,6 +2031,9 @@ void DrawChr() ADD_PlrStringXY(143, 332, 174, a4, a5[0]); } +/** + * @brief Identical to MY_PlrStringXY(x, y, width, pszStr, col, 1) + */ void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col) { BYTE c; @@ -2063,47 +2066,31 @@ void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col) void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base) { - char *v6; // ebx - unsigned char v7; // al - int v8; // edx - int v9; // esi - char *v10; // edi - unsigned char v11; // cl - unsigned char v12; // al - int v13; // edi - int widtha; // [esp+Ch] [ebp-4h] - int widthb; // [esp+Ch] [ebp-4h] - int v16; // [esp+18h] [ebp+8h] - - v6 = pszStr; - widtha = PitchTbl[y + 160] + x + 64; - v7 = *pszStr; - v8 = 0; - v9 = width - x + 1; - v16 = 0; - v10 = pszStr; - if (*pszStr) { - v11 = *pszStr; - do { - ++v10; - v8 += base + fontkern[fontframe[gbFontTransTbl[v11]]]; - v11 = *v10; - } while (*v10); - } - if (v8 < v9) - v16 = (v9 - v8) >> 1; - widthb = v16 + widtha; - while (v7) { - ++v6; - v12 = fontframe[gbFontTransTbl[v7]]; - v13 = v12; - v16 += base + fontkern[v12]; - if (v12) { - if (v16 < v9) - CPrintString(widthb, v12, col); + BYTE c; + char *tmp; + int nOffset, screen_x, line, widthOffset; + + nOffset = x + PitchTbl[y + 160] + 64; + widthOffset = width - x + 1; + line = 0; + screen_x = 0; + tmp = pszStr; + while (*tmp) { + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + base; + } + if (screen_x < widthOffset) + line = (widthOffset - screen_x) >> 1; + nOffset += line; + while (*pszStr) { + c = gbFontTransTbl[(BYTE)*pszStr++]; + c = fontframe[c]; + line += fontkern[c] + base; + if (c) { + if (line < widthOffset) + CPrintString(nOffset, c, col); } - widthb += base + fontkern[v13]; - v7 = *v6; + nOffset += fontkern[c] + base; } } From d4437a923e8367bcaf7026acdfc5ab57c477ac97 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 5 May 2019 22:42:57 +0200 Subject: [PATCH 18/37] Clean control_print_info_str --- Source/control.cpp | 68 +++++++++++++++++----------------------------- Source/control.h | 2 +- 2 files changed, 26 insertions(+), 44 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index aedcb7b5c..6af5b364e 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1742,55 +1742,37 @@ LABEL_33: // 4B8CC1: using guessed type char pcursobj; // 4B8CC2: using guessed type char pcursplr; -void control_print_info_str(int y, char *str, BOOLEAN center, int lines) -{ - int v4; // edi - char *v5; // ebx - unsigned char v6; // cl - signed int v7; // eax - char *v8; // esi - int v9; // eax - unsigned char v10; // esi - unsigned char v11; // al - int width; // [esp+18h] [ebp+Ch] - - v4 = 0; - v5 = str; - width = lineoffset[y + 4 * lines + lines]; +void control_print_info_str(int y, char *str, BOOL center, int lines) +{ + BYTE c; + char *tmp; + int screen_x, line, nOffset; + + line = 0; + nOffset = lineoffset[y + 4 * lines + lines]; if (center == 1) { - v6 = *str; - v7 = 0; - v8 = str; - if (!*str) - goto LABEL_14; - do { - ++v8; - v7 += fontkern[fontframe[gbFontTransTbl[v6]]] + 2; - v6 = *v8; - } while (*v8); - if (v7 < 288) - LABEL_14: - v4 = (288 - v7) >> 1; - width += v4; + screen_x = 0; + tmp = str; + while (*tmp) { + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + 1; + } + if (screen_x < 288) + line = (288 - screen_x) >> 1; + nOffset += line; } - while (1) { - v11 = *v5; - if (!*v5) - break; - ++v5; - v9 = gbFontTransTbl[v11]; - _LOBYTE(v9) = fontframe[v9]; - v10 = (unsigned char)v9; - v4 += fontkern[(unsigned char)v9] + 2; - if ((_BYTE)v9) { - if (v4 < 288) { - CPrintString(width, v10, infoclr); + while (*str) { + c = gbFontTransTbl[(BYTE)*str++]; + c = fontframe[c]; + line += fontkern[c] + 2; + if (c) { + if (line < 288) { + CPrintString(nOffset, c, infoclr); } } - width += fontkern[v10] + 2; + nOffset += fontkern[c] + 2; } } -// 4B883C: using guessed type int infoclr; void PrintGameStr(int x, int y, char *str, int color) { diff --git a/Source/control.h b/Source/control.h index f1057c839..3202ef36b 100644 --- a/Source/control.h +++ b/Source/control.h @@ -85,7 +85,7 @@ void CheckBtnUp(); void FreeControlPan(); BOOL control_WriteStringToBuffer(BYTE *str); void DrawInfoBox(); -void control_print_info_str(int y, char *str, BOOLEAN center, int lines); +void control_print_info_str(int y, char *str, BOOL center, int lines); void PrintGameStr(int x, int y, char *str, int color); void DrawChr(); void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col); From 3c7165b1d8904c1be8d9008bbe4d70dfa276f1c3 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 5 May 2019 22:48:30 +0200 Subject: [PATCH 19/37] Clean up CheckPanelInfo --- Source/control.cpp | 159 +++++++++++++++++---------------------------- 1 file changed, 60 insertions(+), 99 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 6af5b364e..bfb41b889 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -573,10 +573,6 @@ void SetSpell() plr[myplr]._pRSplType = pSplType; } } -// 4B8834: using guessed type int pSpell; -// 4B8954: using guessed type int pSplType; -// 4B8C98: using guessed type int spselflag; -// 52571C: using guessed type int drawpanflag; void SetSpeedSpell(int slot) { @@ -621,7 +617,6 @@ void ToggleSpell(int slot) drawpanflag = 255; } } -// 52571C: using guessed type int drawpanflag; void CPrintString(int nOffset, int nCel, char col) { @@ -1261,7 +1256,6 @@ void ClearCtrlPan() DrawPanelBox(0, sgbPlrTalkTbl + 16, 640, 128, 64, 512); DrawInfoBox(); } -// 4B8840: using guessed type int sgbPlrTalkTbl; void DrawCtrlPan() { @@ -1334,7 +1328,6 @@ void DoSpeedBook() SetCursorPos(X, Y); } -// 4B8C98: using guessed type int spselflag; void DoPanBtn() { @@ -1364,21 +1357,16 @@ void control_set_button_down(int btn_id) void control_check_btn_press() { - int v0; // edx - int v1; // esi - - v0 = MouseX; - v1 = MouseY; if (MouseX >= PanBtnPos[3][0] && MouseX <= PanBtnPos[3][0] + PanBtnPos[3][2] && MouseY >= PanBtnPos[3][1] && MouseY <= PanBtnPos[3][1] + PanBtnPos[3][3]) { control_set_button_down(3); } - if (v0 >= PanBtnPos[6][0] - && v0 <= PanBtnPos[6][0] + PanBtnPos[6][2] - && v1 >= PanBtnPos[6][1] - && v1 <= PanBtnPos[6][1] + PanBtnPos[6][3]) { + if (MouseX >= PanBtnPos[6][0] + && MouseX <= PanBtnPos[6][0] + PanBtnPos[6][2] + && MouseY >= PanBtnPos[6][1] + && MouseY <= PanBtnPos[6][1] + PanBtnPos[6][3]) { control_set_button_down(6); } } @@ -1394,53 +1382,34 @@ void DoAutoMap() InitDiabloMsg(EMSG_NO_AUTOMAP_IN_TOWN); } } -// 679660: using guessed type char gbMaxPlayers; void CheckPanelInfo() { - int v0; // edi - int v1; // eax - int v2; // ecx - int v3; // ecx - int v4; // edi - int v5; // eax - int *v6; // edx - int v7; // ebx - int v8; // ebx - int *v9; // eax - signed int v10; // edx - int v11; // ecx - int v12; // [esp+10h] [ebp-4h] + int i, c, v, s; - v0 = 0; panelflag = 0; ClearPanel(); - if (numpanbtns > 0) { - do { - v1 = v0; - v2 = PanBtnPos[v0][0]; - if (MouseX >= v2 && MouseX <= v2 + PanBtnPos[v1][2]) { - v3 = PanBtnPos[v1][1]; - if (MouseY >= v3 && MouseY <= v3 + PanBtnPos[v1][3]) { - if (v0 == 7) { - if (FriendlyMode) - strcpy(infostr, "Player friendly"); - else - strcpy(infostr, "Player attack"); - } else { - strcpy(infostr, PanBtnStr[v0]); - } - if (PanBtnHotKey[v0]) { - sprintf(tempstr, "Hotkey : %s", PanBtnHotKey[v0]); - AddPanelString(tempstr, 1); - } - infoclr = COL_WHITE; - panelflag = 1; - pinfoflag = TRUE; - } + for (i = 0; i < numpanbtns; i++) { + if (MouseX >= PanBtnPos[i][0] + && MouseX <= PanBtnPos[i][0] + PanBtnPos[i][2] + && MouseY >= PanBtnPos[i][1] + && MouseY <= PanBtnPos[i][1] + PanBtnPos[i][3]) { + if (i != 7) { + strcpy(infostr, PanBtnStr[i]); + } else { + if (FriendlyMode) + strcpy(infostr, "Player friendly"); + else + strcpy(infostr, "Player attack"); } - ++v0; - } while (v0 < numpanbtns); + if (PanBtnHotKey[i]) { + sprintf(tempstr, "Hotkey : %s", PanBtnHotKey[i]); + AddPanelString(tempstr, 1); + } + infoclr = COL_WHITE; + panelflag = 1; + pinfoflag = TRUE; + } } if (!spselflag && MouseX >= 565 && MouseX < 621 && MouseY >= 416 && MouseY < 472) { strcpy(infostr, "Select current spell button"); @@ -1449,62 +1418,58 @@ void CheckPanelInfo() pinfoflag = TRUE; strcpy(tempstr, "Hotkey : 's'"); AddPanelString(tempstr, 1); - v4 = plr[myplr]._pRSpell; - if (v4 != -1) { - switch (_LOBYTE(plr[myplr]._pRSplType)) { + v = plr[myplr]._pRSpell; + if (v != -1) { + switch (plr[myplr]._pRSplType) { case RSPLTYPE_SKILL: - sprintf(tempstr, "%s Skill", spelldata[v4].sSkillText); - LABEL_54: + sprintf(tempstr, "%s Skill", spelldata[v].sSkillText); AddPanelString(tempstr, 1); break; case RSPLTYPE_SPELL: - sprintf(tempstr, "%s Spell", spelldata[v4].sNameText); + sprintf(tempstr, "%s Spell", spelldata[v].sNameText); AddPanelString(tempstr, 1); - v11 = plr[myplr]._pISplLvlAdd + plr[myplr]._pSplLvl[v4]; - if (v11 < 0) - v11 = 0; - if (v11) - sprintf(tempstr, "Spell Level %i", v11); - else + c = plr[myplr]._pISplLvlAdd + plr[myplr]._pSplLvl[v]; + if (c < 0) + c = 0; + if (!c) sprintf(tempstr, "Spell Level 0 - Unusable"); - goto LABEL_54; + else + sprintf(tempstr, "Spell Level %i", c); + AddPanelString(tempstr, 1); + break; case RSPLTYPE_SCROLL: - sprintf(tempstr, "Scroll of %s", spelldata[v4].sNameText); + sprintf(tempstr, "Scroll of %s", spelldata[v].sNameText); AddPanelString(tempstr, 1); - v12 = 0; - v5 = myplr; - if (plr[myplr]._pNumInv > 0) { - v6 = &plr[v5].InvList[0]._iMiscId; - v7 = plr[myplr]._pNumInv; - do { - if (*(v6 - 53) != -1 && (*v6 == IMISC_SCROLL || *v6 == IMISC_SCROLLT) && v6[1] == v4) - ++v12; - v6 += 92; - --v7; - } while (v7); + s = 0; + for (i = 0; i < plr[myplr]._pNumInv; i++) { + if (plr[myplr].InvList[i]._itype != -1 + && (plr[myplr].InvList[i]._iMiscId == IMISC_SCROLL || plr[myplr].InvList[i]._iMiscId == IMISC_SCROLLT) + && plr[myplr].InvList[i]._iSpell == v) { + s++; + } } - v8 = v12; - v9 = &plr[v5].SpdList[0]._iMiscId; - v10 = MAXBELTITEMS; - do { - if (*(v9 - 53) != -1 && (*v9 == IMISC_SCROLL || *v9 == IMISC_SCROLLT) && v9[1] == v4) - ++v8; - v9 += 92; - --v10; - } while (v10); - if (v8 == 1) + for (i = 0; i < MAXBELTITEMS; i++) { + if (plr[myplr].SpdList[i]._itype != -1 + && (plr[myplr].SpdList[i]._iMiscId == IMISC_SCROLL || plr[myplr].SpdList[i]._iMiscId == IMISC_SCROLLT) + && plr[myplr].SpdList[i]._iSpell == v) { + s++; + } + } + if (s == 1) strcpy(tempstr, "1 Scroll"); else - sprintf(tempstr, "%i Scrolls", v8); - goto LABEL_54; + sprintf(tempstr, "%i Scrolls", s); + AddPanelString(tempstr, 1); + break; case RSPLTYPE_CHARGES: - sprintf(tempstr, "Staff of %s", spelldata[v4].sNameText); + sprintf(tempstr, "Staff of %s", spelldata[v].sNameText); AddPanelString(tempstr, 1); if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges == 1) strcpy(tempstr, "1 Charge"); else sprintf(tempstr, "%i Charges", plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges); - goto LABEL_54; + AddPanelString(tempstr, 1); + break; } } } @@ -1592,10 +1557,6 @@ void CheckBtnUp() if (gamemenuOff) gamemenu_off(); } -// 484368: using guessed type int FriendlyMode; -// 4B8960: using guessed type int talkflag; -// 4B8968: using guessed type int sbookflag; -// 646D00: using guessed type char qtextflag; void FreeControlPan() { From 0dd98cab274cb130aaf0fc14675670ad14db20d1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 7 May 2019 00:28:49 +0200 Subject: [PATCH 20/37] Clean up trigs --- Source/cursor.cpp | 6 +++--- Source/trigs.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/cursor.cpp b/Source/cursor.cpp index f88b83507..80b2044ea 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -127,7 +127,7 @@ void CheckTown() || cursmx == missile[mx]._mix - 2 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix - 1 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix && cursmy == missile[mx]._miy) { - trigflag = 1; + trigflag = TRUE; ClearPanel(); strcpy(infostr, "Town Portal"); sprintf(tempstr, "from %s", plr[missile[mx]._misource]._pName); @@ -153,7 +153,7 @@ void CheckRportal() || cursmx == missile[mx]._mix - 2 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix - 1 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix && cursmy == missile[mx]._miy) { - trigflag = 1; + trigflag = TRUE; ClearPanel(); strcpy(infostr, "Portal to"); if (!setlevel) @@ -261,7 +261,7 @@ void CheckCursMove() pcursplr = -1; uitemflag = 0; panelflag = 0; - trigflag = 0; + trigflag = FALSE; if(plr[myplr]._pInvincible) { return; diff --git a/Source/trigs.cpp b/Source/trigs.cpp index e4634bc63..090862aea 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -101,8 +101,8 @@ void InitTownTriggers() numtrigs = 1; - if(gbMaxPlayers == 4) { - for(i = 0; i < 3; i++) { + if(gbMaxPlayers == MAX_PLRS) { + for(i = 0; i < sizeof(townwarps) / sizeof(townwarps[0]); i++) { townwarps[i] = TRUE; } trigs[1]._tx = 49; From aa2752839a7616edf781847025d20495b5c4a2db Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 7 May 2019 00:50:07 +0200 Subject: [PATCH 21/37] Clean up switch style --- Source/automap.cpp | 11 ++++++----- Source/control.cpp | 2 -- Source/list.h | 1 + Source/stores.cpp | 18 +++++++++--------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/automap.cpp b/Source/automap.cpp index e32cf790c..c351b1be2 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -499,6 +499,7 @@ void DrawAutomapPlr() DrawLine(x, y, x - AutoMapYPos, y - AMPlayerX, COLOR_PLAYER); DrawLine(x - AutoMapYPos, y - AMPlayerX, x - AMPlayerX, y - AMPlayerX, COLOR_PLAYER); DrawLine(x - AutoMapYPos, y - AMPlayerX, x - AMPlayerY - AMPlayerX, y, COLOR_PLAYER); + break; } } @@ -589,7 +590,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) { automapview[xx - 1][yy] = 1; } - return; + break; case 3: if (solid) { if (GetAutomapType(xx + 1, yy, FALSE) == 0x4007) @@ -597,7 +598,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) { automapview[xx][yy - 1] = 1; } - return; + break; case 4: if (solid) { if (GetAutomapType(xx, yy + 1, FALSE) == 0x4007) @@ -612,7 +613,7 @@ void SetAutomapView(int x, int y) if (GetAutomapType(xx - 1, yy - 1, FALSE) & 0x4000) automapview[xx - 1][yy - 1] = 1; } - return; + break; case 5: if (solid) { if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) @@ -622,7 +623,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) { automapview[xx - 1][yy] = 1; } - return; + break; case 6: if (solid) { if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) @@ -632,7 +633,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) { automapview[xx][yy - 1] = 1; } - return; + break; } } diff --git a/Source/control.cpp b/Source/control.cpp index bfb41b889..d13865482 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -2175,8 +2175,6 @@ int DrawDurIcon4Item(ItemStruct *item, int x, int frame) case ITYPE_STAFF: frame = 8; break; - default: - break; } } else { frame = 1; diff --git a/Source/list.h b/Source/list.h index 6009b153e..e381c9cee 100644 --- a/Source/list.h +++ b/Source/list.h @@ -151,6 +151,7 @@ void TList::Insert(T *node, InsertPos pos, T *ref) break; case BEFORE: i->InsertBefore(node, reflink); + break; } } diff --git a/Source/stores.cpp b/Source/stores.cpp index 2729a6630..dd9730c6b 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -1818,19 +1818,19 @@ void S_SmithEnter() gossipstart = QUEST_GRISWOLD2; gossipend = QUEST_GRISWOLD13; StartStore(STORE_GOSSIP); - return; + break; case 12: StartStore(STORE_SBUY); - return; + break; case 14: StartStore(STORE_SPBUY); - return; + break; case 16: StartStore(STORE_SSELL); - return; + break; case 18: StartStore(STORE_SREPAIR); - return; + break; case 20: stextflag = STORE_NONE; break; @@ -2536,20 +2536,20 @@ void S_HealerEnter() gossipstart = QUEST_PEPIN2; gossipend = QUEST_PEPIN11; StartStore(STORE_GOSSIP); - return; + break; case 14: if (plr[myplr]._pHitPoints != plr[myplr]._pMaxHP) PlaySFX(IS_CAST8); drawhpflag = TRUE; plr[myplr]._pHitPoints = plr[myplr]._pMaxHP; plr[myplr]._pHPBase = plr[myplr]._pMaxHPBase; - return; + break; case 16: StartStore(STORE_HBUY); - return; + break; case 18: stextflag = STORE_NONE; - return; + break; } } From 0b1b4e806259cd78073cdc5c78c76dcfffff2b93 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Mon, 6 May 2019 20:16:29 -0500 Subject: [PATCH 22/37] PressChar bin exact as C++ (#1136) --- Source/diablo.cpp | 73 ++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 6102dd42b..661e4eadc 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1289,6 +1289,7 @@ void diablo_pause_game() // 525740: using guessed type int PauseMode; // 679660: using guessed type char gbMaxPlayers; +/* NOTE: `return` must be used instead of `break` to be bin exact as C++ */ void PressChar(int vkey) { if(gmenu_exception() || control_talk_last_key(vkey) || sgnTimeoutCurs != 0 || deathflag) { @@ -1314,11 +1315,11 @@ void PressChar(int vkey) case 'G': case 'g': DecreaseGamma(); - break; + return; case 'F': case 'f': IncreaseGamma(); - break; + return; case 'I': case 'i': if(!stextflag) { @@ -1334,7 +1335,7 @@ void PressChar(int vkey) } } } - break; + return; case 'C': case 'c': if(!stextflag) { @@ -1350,7 +1351,7 @@ void PressChar(int vkey) } } } - break; + return; case 'Q': case 'q': if(!stextflag) { @@ -1361,11 +1362,11 @@ void PressChar(int vkey) questlog = FALSE; } } - break; + return; case 'Z': case 'z': zoomflag = zoomflag == 0; - break; + return; case 'S': case 's': if(!stextflag) { @@ -1377,86 +1378,86 @@ void PressChar(int vkey) } track_repeat_walk(0); } - break; + return; case 'B': case 'b': if(!stextflag) { invflag = 0; sbookflag = sbookflag == 0; } - break; + return; case '+': case '=': if(automapflag) { AutomapZoomIn(); } - break; + return; case '-': case '_': if(automapflag) { AutomapZoomOut(); } - break; + return; case 'v': NetSendCmdString(1 << myplr, gszProductName); - break; + return; case 'V': NetSendCmdString(1 << myplr, gszVersionNumber); - break; + return; case '!': case '1': if(plr[myplr].SpdList[0]._itype != -1 && plr[myplr].SpdList[0]._itype != 11) { UseInvItem(myplr, 47); } - break; + return; case '@': case '2': if(plr[myplr].SpdList[1]._itype != -1 && plr[myplr].SpdList[1]._itype != 11) { UseInvItem(myplr, 48); } - break; + return; case '#': case '3': if(plr[myplr].SpdList[2]._itype != -1 && plr[myplr].SpdList[2]._itype != 11) { UseInvItem(myplr, 49); } - break; + return; case '$': case '4': if(plr[myplr].SpdList[3]._itype != -1 && plr[myplr].SpdList[3]._itype != 11) { UseInvItem(myplr, 50); } - break; + return; case '%': case '5': if(plr[myplr].SpdList[4]._itype != -1 && plr[myplr].SpdList[4]._itype != 11) { UseInvItem(myplr, 51); } - break; + return; case '^': case '6': if(plr[myplr].SpdList[5]._itype != -1 && plr[myplr].SpdList[5]._itype != 11) { UseInvItem(myplr, 52); } - break; + return; case '&': case '7': if(plr[myplr].SpdList[6]._itype != -1 && plr[myplr].SpdList[6]._itype != 11) { UseInvItem(myplr, 53); } - break; + return; case '*': case '8': #ifdef _DEBUG if(debug_mode_key_inverted_v || debug_mode_key_w) { NetSendCmd(TRUE, CMD_CHEAT_EXPERIENCE); - break; + return; } #endif if(plr[myplr].SpdList[7]._itype != -1 && plr[myplr].SpdList[7]._itype != 11) { UseInvItem(myplr, 54); } - break; + return; #ifdef _DEBUG case ')': case '0': @@ -1476,52 +1477,52 @@ void PressChar(int vkey) } arrowdebug++; } - break; + return; case ':': if(currlevel == 0 && debug_mode_key_w) { SetAllSpellsCheat(); } - break; + return; case '[': if(currlevel == 0 && debug_mode_key_w) { TakeGoldCheat(); } - break; + return; case ']': if(currlevel == 0 && debug_mode_key_w) { MaxSpellsCheat(); } - break; + return; case 'a': if(debug_mode_key_inverted_v) { spelldata[SPL_TELEPORT].sTownSpell = 1; plr[myplr]._pSplLvl[plr[myplr]._pSpell]++; } - break; + return; case 'D': PrintDebugPlayer(TRUE); - break; + return; case 'd': PrintDebugPlayer(FALSE); - break; + return; case 'e': if(debug_mode_key_d) { sprintf(tempstr, "EFlag = %i", plr[myplr]._peflag); NetSendCmdString(1 << myplr, tempstr); } - break; + return; case 'L': case 'l': if(debug_mode_key_inverted_v) { ToggleLighting(); } - break; + return; case 'M': NextDebugMonster(); - break; + return; case 'm': GetDebugMonster(); - break; + return; case 'R': case 'r': sprintf(tempstr, "seed = %i", glSeedTbl[currlevel]); @@ -1530,7 +1531,7 @@ void PressChar(int vkey) NetSendCmdString(1 << myplr, tempstr); sprintf(tempstr, "End = %i", glEndSeed[currlevel]); NetSendCmdString(1 << myplr, tempstr); - break; + return; case 'T': case 't': if(debug_mode_key_inverted_v) { @@ -1539,17 +1540,17 @@ void PressChar(int vkey) sprintf(tempstr, "CX = %i CY = %i DP = %i", cursmx, cursmy, dungeon[cursmx][cursmy]); NetSendCmdString(1 << myplr, tempstr); } - break; + return; case '|': if(currlevel == 0 && debug_mode_key_w) { GiveGoldCheat(); } - break; + return; case '~': if(currlevel == 0 && debug_mode_key_w) { StoresCheat(); } - break; + return; #endif } } From 1faa84481b0ab08a42166d44cc8e7e4427a78c69 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Mon, 6 May 2019 23:20:13 +0300 Subject: [PATCH 23/37] Make SpawnUnique bin exact. --- Source/items.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index eb0e5d897..a8a4ad6bd 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1990,24 +1990,23 @@ void SpawnUnique(int uid, int x, int y) { int ii, itype; - if (numitems < MAXITEMS) { - ii = itemavail[0]; - GetSuperItemSpace(x, y, itemavail[0]); - itype = 0; - itemactive[numitems] = ii; - itemavail[0] = itemavail[MAXITEMS - numitems - 1]; + if (numitems >= MAXITEMS) + return; - if (AllItemsList[0].iItemId != UniqueItemList[uid].UIItemId) { - while (AllItemsList[itype].iItemId != UniqueItemList[uid].UIItemId) { - itype++; - } - } + ii = itemavail[0]; + GetSuperItemSpace(x, y, ii); + itemavail[0] = itemavail[MAXITEMS - numitems - 1]; + itemactive[numitems] = ii; - GetItemAttrs(ii, itype, currlevel); - GetUniqueItem(ii, uid); - SetupItem(ii); - numitems++; + itype = 0; + while (AllItemsList[itype].iItemId != UniqueItemList[uid].UIItemId) { + itype++; } + + GetItemAttrs(ii, itype, currlevel); + GetUniqueItem(ii, uid); + SetupItem(ii); + numitems++; } void ItemRndDur(int ii) From c917609784fd061eb1c6526190d2810858ba9dda Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Mon, 6 May 2019 23:22:04 +0300 Subject: [PATCH 24/37] Make GetItemStr bin exact. Inverted if like a boss. --- Source/items.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index a8a4ad6bd..35ee3b388 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2467,10 +2467,10 @@ void GetItemStr(int i) int nGold; if (item[i]._itype != ITYPE_GOLD) { - if (!item[i]._iIdentified) - strcpy(infostr, item[i]._iName); - else + if (item[i]._iIdentified) strcpy(infostr, item[i]._iIName); + else + strcpy(infostr, item[i]._iName); if (item[i]._iMagical == ITEM_QUALITY_MAGIC) infoclr = COL_BLUE; From 5818618e3a84bdf8a970f158e5501fe3d279d9d6 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 7 May 2019 21:42:33 +0200 Subject: [PATCH 25/37] Clean up RespawnItem --- Source/items.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/items.cpp b/Source/items.cpp index 35ee3b388..12bdb9ba7 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2369,10 +2369,10 @@ void RespawnItem(int i, BOOL FlipFlag) it = ItemCAnimTbl[item[i]._iCurs]; item[i]._iAnimData = itemanims[it]; item[i]._iAnimLen = ItemAnimLs[it]; - item[i]._iRequest = FALSE; item[i]._iAnimWidth = 96; item[i]._iAnimWidth2 = 16; item[i]._iPostDraw = FALSE; + item[i]._iRequest = FALSE; if (FlipFlag) { item[i]._iAnimFrame = 1; item[i]._iAnimFlag = TRUE; From 438eec5017e6e2b19072ff314fb174ce7c2ac63b Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 6 May 2019 03:07:45 +0200 Subject: [PATCH 26/37] Clean up SetAutomapView --- Source/automap.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/automap.cpp b/Source/automap.cpp index e32cf790c..1312ee946 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -589,7 +589,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) { automapview[xx - 1][yy] = 1; } - return; + break; case 3: if (solid) { if (GetAutomapType(xx + 1, yy, FALSE) == 0x4007) @@ -597,7 +597,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) { automapview[xx][yy - 1] = 1; } - return; + break; case 4: if (solid) { if (GetAutomapType(xx, yy + 1, FALSE) == 0x4007) @@ -612,7 +612,7 @@ void SetAutomapView(int x, int y) if (GetAutomapType(xx - 1, yy - 1, FALSE) & 0x4000) automapview[xx - 1][yy - 1] = 1; } - return; + break; case 5: if (solid) { if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) @@ -622,7 +622,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) { automapview[xx - 1][yy] = 1; } - return; + break; case 6: if (solid) { if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) @@ -632,7 +632,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) { automapview[xx][yy - 1] = 1; } - return; + break; } } From ee9f5ce511dddcd3dc9b0fd9b272948b1dd7afc8 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Sun, 5 May 2019 14:30:38 +0300 Subject: [PATCH 27/37] Clean up MAI_Snake. --- Source/monster.cpp | 227 ++++++++++++++------------------------------- 1 file changed, 69 insertions(+), 158 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index b07b6b827..ec197fc0c 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3038,173 +3038,84 @@ BOOL MAI_Path(int i) void MAI_Snake(int i) { - int esi1; // esi - MonsterStruct *esi3; // esi - BOOLEAN v3; // zf - int v4; // ecx - int v5; // eax - int v6; // ST1C_4 - int v7; // edi - int v8; // edx - int v9; // ST18_4 - int v10; // ebx - int v11; // eax - //int v12; // ST1C_4 - int v14; // eax - int v15; // eax - int v16; // ecx - int v17; // edx - int v18; // ecx - int v19; // eax - //int v20; // ST1C_4 - int v22; // eax - //int v23; // ST1C_4 - int v24; // ebx - int v26; // ecx - int v27; // eax - int v28; // ecx - int v29; // ecx - int v30; // eax - int v31; // edx - int v32; // eax - int v33; // ecx - int v34; // ecx - int v35; // eax - char pattern[6]; // [esp+4h] [ebp-1Ch] - int micaster; // [esp+Ch] [ebp-14h] - int midir; // [esp+10h] [ebp-10h] - int v1; // [esp+14h] [ebp-Ch] - int v2; // [esp+18h] [ebp-8h] - int arglist; // [esp+1Ch] [ebp-4h] + MonsterStruct *Monst; + int fx, fy, mx, my, md; + int pnum; + int tmp; - esi1 = i; - arglist = i; if ((DWORD)i >= MAXMONSTERS) app_fatal("MAI_Snake: Invalid monster %d", i); - pattern[2] = 0; - pattern[3] = -1; - pattern[4] = -1; - pattern[5] = 0; - esi3 = &monster[esi1]; - pattern[0] = 1; - pattern[1] = 1; - v3 = esi3->_mmode == MM_STAND; - micaster = esi3->_menemy; - if (v3 && esi3->_msquelch) { - v4 = esi3->_mx; - v5 = (unsigned char)esi3->_menemyy; - v6 = esi3->_lasty; - v1 = (unsigned char)esi3->_menemyx; - v7 = v4 - v1; - v8 = esi3->_my; - v9 = esi3->_lastx; - v2 = v5; - v10 = v8 - v5; - midir = GetDirection(v4, v8, v9, v6); - esi3->_mdir = midir; - if (abs(v7) < 2) { - v11 = abs(v10); - //v13 = v12; - if (v11 < 2) { - v14 = esi3->_mVar1; - if (v14 == MM_DELAY - || v14 == MM_CHARGE - || (v15 = random(105, 100), v16 = (unsigned char)esi3->_mint + 20, v15 < v16)) { - M_StartAttack(arglist); - LABEL_49: - if (esi3->_mmode == MM_STAND) - esi3->_mAnimData = esi3->MType->Anims[MA_STAND].Data[esi3->_mdir]; - return; - } - v17 = 10 - (unsigned char)esi3->_mint + random(105, 10); - v18 = arglist; - LABEL_11: - M_StartDelay(v18, v17); - goto LABEL_49; - } - } - v19 = abs(v7); - //v21 = v20; - if (v19 >= 3 || (v22 = abs(v10), v22 >= 3)) /* v21 = v23, */ - { - v24 = arglist; - } else { - v24 = arglist; - if (LineClearF1(PosOkMonst, arglist, esi3->_mx, esi3->_my, v1, v2) && esi3->_mVar1 != MM_CHARGE) { - if (AddMissile(esi3->_mx, esi3->_my, v1, v2, midir, MIS_RHINO, micaster, arglist, 0, 0) != -1) { - PlayEffect(arglist, 0); - v26 = esi3->_my + 112 * esi3->_mx; - esi3->_mmode = MM_CHARGE; - dMonster[0][v26] = -1 - v24; - } - goto LABEL_49; - } - } - if (esi3->_mVar1 != MM_DELAY) { - v27 = random(106, 100); - v28 = 2 * (unsigned char)esi3->_mint; - if (v27 < 35 - v28) { - v17 = 15 - (unsigned char)esi3->_mint + random(106, 10); - v18 = v24; - goto LABEL_11; - } - } - v29 = esi3->_mgoalvar1; - v30 = midir + pattern[v29]; - if (v30 >= 0) { - v31 = v30 - 8; - if (v30 < 8) - v31 = midir + pattern[v29]; - } else { - v31 = v30 + 8; - } - esi3->_mgoalvar1 = v29 + 1; - if (v29 + 1 > 5) - esi3->_mgoalvar1 = 0; - v32 = esi3->_mgoalvar2; - v33 = v31 - v32; - if (v31 - v32 >= 0) { - if (v33 >= 8) - v33 -= 8; - } else { - v33 += 8; - } - if (v33 <= 0) { - LABEL_47: - if (!M_DumbWalk(v24, esi3->_mgoalvar2)) - M_CallWalk2(v24, esi3->_mdir); - goto LABEL_49; - } - if (v33 >= 4) { - if (v33 == 4) { - esi3->_mgoalvar2 = v31; - goto LABEL_47; + char pattern[6] = { 1, 1, 0, -1, -1, 0 }; + Monst = monster + i; + pnum = Monst->_menemy; + if (Monst->_mmode != MM_STAND || !Monst->_msquelch) + return; + fx = Monst->_menemyx; + fy = Monst->_menemyy; + mx = Monst->_mx - fx; + my = Monst->_my - fy; + md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); + Monst->_mdir = md; + if (abs(mx) >= 2 || abs(my) >= 2) { + if (abs(mx) < 3 && abs(my) < 3 && LineClearF1(PosOkMonst, i, Monst->_mx, Monst->_my, fx, fy) && Monst->_mVar1 != MM_CHARGE) { + if (AddMissile(Monst->_mx, Monst->_my, fx, fy, md, MIS_RHINO, pnum, i, 0, 0) != -1) { + PlayEffect(i, 0); + Monst->_mmode = MM_CHARGE; + dMonster[Monst->_mx][Monst->_my] = -1 - i; } - v34 = v32 - 1; - if (v32 - 1 < 0) { - v35 = v32 + 7; - goto LABEL_46; + } else if (Monst->_mVar1 == MM_DELAY || random(106, 100) >= 35 - 2 * Monst->_mint) { + if (md + pattern[Monst->_mgoalvar1] < 0) { + tmp = md + pattern[Monst->_mgoalvar1] + 8; + } else { + tmp = md + pattern[Monst->_mgoalvar1] - 8; + if (md + pattern[Monst->_mgoalvar1] < 8) + tmp = md + pattern[Monst->_mgoalvar1]; } - if (v34 >= 8) { - v35 = v32 - 9; - goto LABEL_46; + Monst->_mgoalvar1++; + if (Monst->_mgoalvar1 > 5) + Monst->_mgoalvar1 = 0; + if (tmp - Monst->_mgoalvar2 < 0) { + md = tmp - Monst->_mgoalvar2 + 8; + } else if (tmp - Monst->_mgoalvar2 >= 8) { + md = tmp - Monst->_mgoalvar2 - 8; + } else + md = tmp - Monst->_mgoalvar2; + if (md > 0) { + if (md < 4) { + if (Monst->_mgoalvar2 + 1 < 0) { + md = Monst->_mgoalvar2 + 9; + } else if (Monst->_mgoalvar2 + 1 >= 8) { + md = Monst->_mgoalvar2 - 7; + } else + md = Monst->_mgoalvar2 + 1; + Monst->_mgoalvar2 = md; + } else if (md == 4) { + Monst->_mgoalvar2 = tmp; + } else { + if (Monst->_mgoalvar2 - 1 < 0) { + md = Monst->_mgoalvar2 + 7; + } else if (Monst->_mgoalvar2 - 1 >= 8) { + md = Monst->_mgoalvar2 - 9; + } else + md = Monst->_mgoalvar2 - 1; + Monst->_mgoalvar2 = md; + } } + if (!M_DumbWalk(i, Monst->_mgoalvar2)) + M_CallWalk2(i, Monst->_mdir); } else { - v34 = v32 + 1; - if (v32 + 1 < 0) { - v35 = v32 + 9; - LABEL_46: - esi3->_mgoalvar2 = v35; - goto LABEL_47; - } - if (v34 >= 8) { - v35 = v32 - 7; - goto LABEL_46; - } + M_StartDelay(i, 15 - Monst->_mint + random(106, 10)); } - v35 = v34; - goto LABEL_46; + } else { + if (Monst->_mVar1 == MM_DELAY + || Monst->_mVar1 == MM_CHARGE + || (random(105, 100) < Monst->_mint + 20)) { + M_StartAttack(i); + } else + M_StartDelay(i, 10 - Monst->_mint + random(105, 10)); } + if (Monst->_mmode == MM_STAND) + Monst->_mAnimData = Monst->MType->Anims[MA_STAND].Data[Monst->_mdir]; } void MAI_Bat(int i) From 8a142d3c46e28de3935524dd18b8864ec2850d50 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Wed, 8 May 2019 00:32:50 +0200 Subject: [PATCH 28/37] Clean up multi_event_handler --- 3rdParty/Storm/Source/storm.cpp | 4 +-- 3rdParty/Storm/Source/storm.h | 4 +-- Source/multi.cpp | 45 +++++++++++++-------------------- Source/multi.h | 2 +- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/3rdParty/Storm/Source/storm.cpp b/3rdParty/Storm/Source/storm.cpp index 583be190c..180521443 100644 --- a/3rdParty/Storm/Source/storm.cpp +++ b/3rdParty/Storm/Source/storm.cpp @@ -231,8 +231,8 @@ BOOLEAN __stdcall SFileSetBasePath(char *) rBool; void __cdecl SDrawRealizePalette(void) rVoid; BOOL __cdecl SVidPlayContinue(void) rBool; BOOL __stdcall SNetGetOwnerTurnsWaiting(DWORD *) rBool; -void * __stdcall SNetUnregisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)) rPVoid; -void * __stdcall SNetRegisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)) rPVoid; +BOOL __stdcall SNetUnregisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)) rPVoid; +BOOL __stdcall SNetRegisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)) rPVoid; BOOLEAN __stdcall SNetSetBasePlayer(int) rBool; int __stdcall SNetInitializeProvider(unsigned long,struct _SNETPROGRAMDATA *,struct _SNETPLAYERDATA *,struct _SNETUIDATA *,struct _SNETVERSIONDATA *) rInt; int __stdcall SNetGetProviderCaps(struct _SNETCAPS *) rInt; diff --git a/3rdParty/Storm/Source/storm.h b/3rdParty/Storm/Source/storm.h index d765bf160..adb798f82 100644 --- a/3rdParty/Storm/Source/storm.h +++ b/3rdParty/Storm/Source/storm.h @@ -1316,8 +1316,8 @@ BOOLEAN __stdcall SFileSetBasePath(char *); void __cdecl SDrawRealizePalette(void); BOOL __cdecl SVidPlayContinue(void); BOOL __stdcall SNetGetOwnerTurnsWaiting(DWORD *); -void * __stdcall SNetUnregisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)); -void * __stdcall SNetRegisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)); +BOOL __stdcall SNetUnregisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)); +BOOL __stdcall SNetRegisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)); BOOLEAN __stdcall SNetSetBasePlayer(int); int __stdcall SNetInitializeProvider(unsigned long,struct _SNETPROGRAMDATA *,struct _SNETPLAYERDATA *,struct _SNETUIDATA *,struct _SNETVERSIONDATA *); int __stdcall SNetGetProviderCaps(struct _SNETCAPS *); diff --git a/Source/multi.cpp b/Source/multi.cpp index 51066cd32..c97f894a8 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -609,35 +609,29 @@ void NetClose() nthread_cleanup(); dthread_cleanup(); tmsg_cleanup(); - multi_event_handler(0); + multi_event_handler(FALSE); SNetLeaveGame(3); msgcmd_cmd_cleanup(); if (gbMaxPlayers > 1) Sleep(2000); } -char multi_event_handler(int a1) -{ - int v1; // edi - void *(__stdcall * v2)(int, void(__stdcall *)(_SNETEVENT *)); // ebx - unsigned int v3; // esi - int v4; // eax - char *v5; // eax - - v1 = a1; - v2 = SNetRegisterEventHandler; - if (!a1) - v2 = SNetUnregisterEventHandler; - v3 = 0; - do { - v4 = (int)v2(event_types[v3], multi_handle_events); - if (!v4 && v1) { - v5 = TraceLastError(); - app_fatal("SNetRegisterEventHandler:\n%s", v5); +void multi_event_handler(BOOL add) +{ + DWORD i; + BOOL(__stdcall * fn) + (int, void(__stdcall *)(_SNETEVENT *)); + + if (add) + fn = SNetRegisterEventHandler; + else + fn = SNetUnregisterEventHandler; + + for (i = 0; i < 3; i++) { + if (!fn(event_types[i], multi_handle_events) && add) { + app_fatal("SNetRegisterEventHandler:\n%s", TraceLastError()); } - ++v3; - } while (v3 < 3); - return v4; + } } void __stdcall multi_handle_events(_SNETEVENT *pEvt) @@ -774,11 +768,6 @@ BOOL NetInit(BOOL bSinglePlayer, BOOL *pfExitProgram) return TRUE; } -// 6761B8: using guessed type char gbSomebodyWonGameKludge; -// 67862D: using guessed type char gbGameDestroyed; -// 678640: using guessed type char byte_678640; -// 6796E4: using guessed type char gbDeltaSender; -// 6796E8: using guessed type int sgbNetInited; void buffer_init(TBuffer *pBuf) { @@ -877,7 +866,7 @@ BOOL multi_init_multi(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info, plr[0].pBattleNet = 1; } - multi_event_handler(1); + multi_event_handler(TRUE); if (UiSelectGame(1, client_info, user_info, ui_info, &fileinfo, &playerId)) break; diff --git a/Source/multi.h b/Source/multi.h index 6e9e103e3..26330aa5f 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -43,7 +43,7 @@ void multi_handle_all_packets(int players, TPkt *packet, int a3); void multi_process_tmsgs(); void multi_send_zero_packet(int pnum, char a2, void *pbSrc, int dwLen); void NetClose(); -char multi_event_handler(int a1); +void multi_event_handler(BOOL add); void __stdcall multi_handle_events(_SNETEVENT *pEvt); BOOL NetInit(BOOL bSinglePlayer, BOOL *pfExitProgram); void buffer_init(TBuffer *pBuf); From ddf0e0b29f5cd94af2b6cb148d8862b63027f7b4 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Wed, 8 May 2019 07:14:09 -0500 Subject: [PATCH 29/37] MI_Lightctrl --- Source/missiles.cpp | 146 +++++++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 68 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 43d9cf733..d1f61983b 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3186,80 +3186,90 @@ void MI_Fireball(int i) void MI_Lightctrl(int i) { - int v1; // esi - int v2; // eax - int v3; // eax - int v5; // edi - signed int v6; // ebx - signed int v7; // edx - int v8; // ecx - int v9; // eax - int v10; // [esp-10h] [ebp-24h] - int v11; // [esp-Ch] [ebp-20h] - int v12; // [esp-8h] [ebp-1Ch] - int v13; // [esp+Ch] [ebp-8h] - int ia; // [esp+10h] [ebp-4h] + int pn, dam, p, mx, my; - ia = i; - v1 = i; - v2 = missile[i]._misource; - --missile[v1]._mirange; - if (v2 == -1) { - v5 = random(81, currlevel) + 2 * currlevel; - } else if (missile[v1]._micaster) { - v5 = 2 - * ((unsigned char)monster[v2].mMinDamage - + random(80, (unsigned char)monster[v2].mMaxDamage - (unsigned char)monster[v2].mMinDamage + 1)); - } else { - v3 = random(79, plr[v2]._pLevel); - v5 = (v3 + random(79, 2) + 2) << 6; - } - missile[v1]._mitxoff += missile[v1]._mixvel; - missile[v1]._mityoff += missile[v1]._miyvel; - GetMissilePos(ia); - v6 = missile[v1]._mix; - v7 = missile[v1]._miy; - v8 = missile[v1]._misource; - v13 = missile[v1]._miy; - v9 = dPiece[missile[v1]._mix][v7]; - if (v8 != -1 || v6 != missile[v1]._misx || v7 != missile[v1]._misy) { - if (!nMissileTable[v9]) - goto LABEL_12; - missile[v1]._mirange = 0; - } - if (!nMissileTable[v9]) { - LABEL_12: - if (v6 == missile[v1]._miVar1 && v7 == missile[v1]._miVar2 || v6 <= 0 || v7 <= 0 || v6 >= MAXDUNX || v7 >= MAXDUNY) - goto LABEL_27; - if (v8 == -1) { - v12 = missile[v1]._mispllvl; - v11 = v5; - v10 = -1; + /// ASSERT: assert((DWORD)i < MAXMISSILES); + missile[i]._mirange--; + + p = missile[i]._misource; + if(p != -1) { + if(missile[i]._micaster == 0) { + dam = (random(79, 2) + random(79, plr[p]._pLevel) + 2) << 6; } else { - if (missile[v1]._micaster == 1) { - v9 = (int)monster[v8].MType; - _LOBYTE(v9) = *(_BYTE *)v9; - if ((unsigned char)v9 >= MT_STORM && (unsigned char)v9 <= MT_MAEL) { - _LOBYTE(v9) = missile[v1]._micaster; - AddMissile(v6, v7, missile[v1]._misx, missile[v1]._misy, ia, MIS_LIGHTNING2, v9, v8, v5, missile[v1]._mispllvl); - LABEL_26: - v7 = v13; - missile[v1]._miVar1 = missile[v1]._mix; - missile[v1]._miVar2 = missile[v1]._miy; - goto LABEL_27; + dam = 2 * (monster[p].mMinDamage + random(80, monster[p].mMaxDamage - monster[p].mMinDamage + 1)); + } + } else { + dam = random(81, currlevel) + 2 * currlevel; + } + + missile[i]._mitxoff += missile[i]._mixvel; + missile[i]._mityoff += missile[i]._miyvel; + GetMissilePos(i); + + mx = missile[i]._mix; + my = missile[i]._miy; + /// ASSERT: assert((DWORD)mx < MAXDUNX); + /// ASSERT: assert((DWORD)my < MAXDUNY); + pn = dPiece[mx][my]; + /// ASSERT: assert((DWORD)pn <= MAXTILES); + + if(missile[i]._misource == -1) { + if((mx != missile[i]._misx || my != missile[i]._misy) && nMissileTable[pn] != 0) { + missile[i]._mirange = 0; + } + } else if(nMissileTable[pn] != 0) { + missile[i]._mirange = 0; + } + if(nMissileTable[pn] == 0) { + if((mx != missile[i]._miVar1 || my != missile[i]._miVar2) && mx > 0 && my > 0 && mx < MAXDUNX && my < MAXDUNY) { + if(missile[i]._misource != -1) { + if(missile[i]._micaster == 1 + && monster[missile[i]._misource].MType->mtype >= MT_STORM + && monster[missile[i]._misource].MType->mtype <= MT_MAEL) { + AddMissile( + mx, + my, + missile[i]._misx, + missile[i]._misy, + i, + MIS_LIGHTNING2, + missile[i]._micaster, + missile[i]._misource, + dam, + missile[i]._mispllvl); + } else { + AddMissile( + mx, + my, + missile[i]._misx, + missile[i]._misy, + i, + MIS_LIGHTNING, + missile[i]._micaster, + missile[i]._misource, + dam, + missile[i]._mispllvl); } + } else { + AddMissile( + mx, + my, + missile[i]._misx, + missile[i]._misy, + i, + MIS_LIGHTNING, + missile[i]._micaster, + missile[i]._misource, + dam, + missile[i]._mispllvl); } - v12 = missile[v1]._mispllvl; - v11 = v5; - v10 = v8; + missile[i]._miVar1 = missile[i]._mix; + missile[i]._miVar2 = missile[i]._miy; } - _LOBYTE(v9) = missile[v1]._micaster; - AddMissile(v6, v7, missile[v1]._misx, missile[v1]._misy, ia, MIS_LIGHTNING, v9, v10, v11, v12); - goto LABEL_26; } -LABEL_27: - if (!missile[v1]._mirange || v6 <= 0 || v7 <= 0 || v6 >= MAXDUNX || v7 > MAXDUNY) - missile[v1]._miDelFlag = TRUE; + if(missile[i]._mirange == 0 || mx <= 0 || my <= 0 || mx >= MAXDUNX || my > MAXDUNY) { + missile[i]._miDelFlag = TRUE; + } } void MI_Lightning(int i) From 4a8f9fb96430501f72be1c8902f2d0d791f9e712 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 7 May 2019 03:14:39 +0200 Subject: [PATCH 30/37] Clean up nthread_terminate_game --- Source/multi.cpp | 2 +- Source/nthread.cpp | 36 +++++++++++++----------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Source/multi.cpp b/Source/multi.cpp index c97f894a8..3da4db9c8 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -15,7 +15,7 @@ BOOLEAN sgbPlayerLeftGameTbl[MAX_PLRS]; int sgbSentThisCycle; // idb BOOL gbShouldValidatePackage; BYTE gbActivePlayers; // weak -BOOLEAN gbGameDestroyed; // weak +BOOLEAN gbGameDestroyed; BOOLEAN sgbSendDeltaTbl[MAX_PLRS]; _gamedata sgGameInitInfo; char byte_678640; // weak diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 4019599f0..813120821 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -25,18 +25,19 @@ static HANDLE sghThread = INVALID_HANDLE_VALUE; void nthread_terminate_game(const char *pszFcn) { - DWORD sErr; // eax + DWORD sErr; sErr = SErrGetLastError(); - if (sErr != STORM_ERROR_INVALID_PLAYER) { - if (sErr == STORM_ERROR_GAME_TERMINATED || sErr == STORM_ERROR_NOT_IN_GAME) { - gbGameDestroyed = 1; - } else { - app_fatal("%s:\n%s", pszFcn, TraceLastError()); - } + if (sErr == STORM_ERROR_INVALID_PLAYER) { + return; + } else if (sErr == STORM_ERROR_GAME_TERMINATED) { + gbGameDestroyed = TRUE; + } else if (sErr == STORM_ERROR_NOT_IN_GAME) { + gbGameDestroyed = TRUE; + } else { + app_fatal("%s:\n%s", pszFcn, TraceLastError()); } } -// 67862D: using guessed type char gbGameDestroyed; int nthread_send_and_recv_turn(int cur_turn, int turn_delta) { @@ -118,7 +119,6 @@ void nthread_set_turn_upper_bit() { turn_upper_bit = 0x80000000; } -// 679754: using guessed type int turn_upper_bit; void nthread_start(BOOL set_turn_upper_bit) { @@ -196,8 +196,8 @@ void nthread_start(BOOL set_turn_upper_bit) unsigned int __stdcall nthread_handler(void *a1) { - signed int delta; // esi - int received; // [esp+Ch] [ebp-4h] + int delta; + int received; if (nthread_should_run) { while (1) { @@ -225,8 +225,6 @@ unsigned int __stdcall nthread_handler(void *a1) } return 0; } -// 679734: using guessed type char nthread_should_run; -// 679764: using guessed type int last_tick; void nthread_cleanup() { @@ -246,11 +244,6 @@ void nthread_cleanup() sghThread = (HANDLE)-1; } } -// 679734: using guessed type char nthread_should_run; -// 679738: using guessed type int gdwTurnsInTransit; -// 67975A: using guessed type char sgbThreadIsRunning; -// 67975C: using guessed type int gdwLargestMsgSize; -// 679760: using guessed type int gdwNormalMsgSize; void nthread_ignore_mutex(BOOL bStart) { @@ -264,12 +257,11 @@ void nthread_ignore_mutex(BOOL bStart) sgbThreadIsRunning = bStart; } } -// 67975A: using guessed type char sgbThreadIsRunning; BOOL nthread_has_500ms_passed(BOOL unused) { - DWORD currentTickCount; // eax - int ticksElapsed; // ecx + DWORD currentTickCount; + int ticksElapsed; currentTickCount = GetTickCount(); ticksElapsed = currentTickCount - last_tick; @@ -279,5 +271,3 @@ BOOL nthread_has_500ms_passed(BOOL unused) } return ticksElapsed >= 0; } -// 679660: using guessed type char gbMaxPlayers; -// 679764: using guessed type int last_tick; From 790197cae51d5ea06271c73303f12e900c6657f8 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Wed, 8 May 2019 17:24:57 +0200 Subject: [PATCH 31/37] Define SEVTHANDLER --- 3rdParty/Storm/Source/storm.cpp | 4 ++-- 3rdParty/Storm/Source/storm.h | 12 ++++++++++-- Source/multi.cpp | 5 ++--- Source/multi.h | 2 ++ structs.h | 9 --------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/3rdParty/Storm/Source/storm.cpp b/3rdParty/Storm/Source/storm.cpp index 180521443..da7688b08 100644 --- a/3rdParty/Storm/Source/storm.cpp +++ b/3rdParty/Storm/Source/storm.cpp @@ -231,8 +231,8 @@ BOOLEAN __stdcall SFileSetBasePath(char *) rBool; void __cdecl SDrawRealizePalette(void) rVoid; BOOL __cdecl SVidPlayContinue(void) rBool; BOOL __stdcall SNetGetOwnerTurnsWaiting(DWORD *) rBool; -BOOL __stdcall SNetUnregisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)) rPVoid; -BOOL __stdcall SNetRegisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)) rPVoid; +BOOL __stdcall SNetUnregisterEventHandler(int,SEVTHANDLER) rPVoid; +BOOL __stdcall SNetRegisterEventHandler(int,SEVTHANDLER) rPVoid; BOOLEAN __stdcall SNetSetBasePlayer(int) rBool; int __stdcall SNetInitializeProvider(unsigned long,struct _SNETPROGRAMDATA *,struct _SNETPLAYERDATA *,struct _SNETUIDATA *,struct _SNETVERSIONDATA *) rInt; int __stdcall SNetGetProviderCaps(struct _SNETCAPS *) rInt; diff --git a/3rdParty/Storm/Source/storm.h b/3rdParty/Storm/Source/storm.h index adb798f82..c66f36752 100644 --- a/3rdParty/Storm/Source/storm.h +++ b/3rdParty/Storm/Source/storm.h @@ -372,6 +372,14 @@ typedef struct _s_evt DWORD dwSize; } S_EVT, *PS_EVT; +typedef struct _SNETEVENT { + int eventid; + int playerid; + void *data; + int databytes; +} _SNETEVENT; + +typedef void (STORMAPI *SEVTHANDLER)(struct _SNETEVENT *); // @TODO: "type" is unknown. //HANDLE STORMAPI SNetRegisterEventHandler(int type, void (STORMAPI *sEvent)(PS_EVT)); @@ -1316,8 +1324,8 @@ BOOLEAN __stdcall SFileSetBasePath(char *); void __cdecl SDrawRealizePalette(void); BOOL __cdecl SVidPlayContinue(void); BOOL __stdcall SNetGetOwnerTurnsWaiting(DWORD *); -BOOL __stdcall SNetUnregisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)); -BOOL __stdcall SNetRegisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)); +BOOL __stdcall SNetUnregisterEventHandler(int,SEVTHANDLER); +BOOL __stdcall SNetRegisterEventHandler(int,SEVTHANDLER); BOOLEAN __stdcall SNetSetBasePlayer(int); int __stdcall SNetInitializeProvider(unsigned long,struct _SNETPROGRAMDATA *,struct _SNETPLAYERDATA *,struct _SNETUIDATA *,struct _SNETVERSIONDATA *); int __stdcall SNetGetProviderCaps(struct _SNETCAPS *); diff --git a/Source/multi.cpp b/Source/multi.cpp index 3da4db9c8..6e1eb5cf1 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -1,5 +1,4 @@ #include "diablo.h" -#include "../3rdParty/Storm/Source/storm.h" #include "../DiabloUI/diabloui.h" BOOLEAN gbSomebodyWonGameKludge; // weak @@ -619,8 +618,8 @@ void NetClose() void multi_event_handler(BOOL add) { DWORD i; - BOOL(__stdcall * fn) - (int, void(__stdcall *)(_SNETEVENT *)); + BOOL(STORMAPI * fn) + (int, SEVTHANDLER); if (add) fn = SNetRegisterEventHandler; diff --git a/Source/multi.h b/Source/multi.h index 26330aa5f..142ae8268 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -2,6 +2,8 @@ #ifndef __MULTI_H__ #define __MULTI_H__ +#include "../3rdParty/Storm/Source/storm.h" + extern BOOLEAN gbSomebodyWonGameKludge; // weak extern char szPlayerDescript[128]; extern WORD sgwPackPlrOffsetTbl[MAX_PLRS]; diff --git a/structs.h b/structs.h index 625474f2f..09299c300 100644 --- a/structs.h +++ b/structs.h @@ -1247,8 +1247,6 @@ typedef struct _uiheroinfo { // storm ////////////////////////////////////////////////// -// TPDEF PTR FCN VOID SEVTHANDLER - // TPDEF PTR FCN UCHAR SMSGIDLEPROC // TPDEF PTR FCN VOID SMSGHANDLER @@ -1264,13 +1262,6 @@ typedef struct _SNETCAPS { int defaultturnsintransit; } _SNETCAPS; -typedef struct _SNETEVENT { - int eventid; - int playerid; - void *data; - int databytes; -} _SNETEVENT; - // TPDEF PTR FCN UCHAR SNETABORTPROC // TPDEF PTR FCN UCHAR SNETCATEGORYPROC // TPDEF PTR FCN UCHAR SNETCHECKAUTHPROC From 1cc8c8163675aa0ee82ff7fb10d864b2251d4444 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Wed, 8 May 2019 16:40:35 -0500 Subject: [PATCH 32/37] Change PKWare to static library (#1141) --- 3rdParty/PKWare/Makefile | 59 ++++++++++++++++++++++ 3rdParty/PKWare/Pkware.dsp | 100 +++++++++++++++++++++++++++++++++++++ Diablo.dsp | 18 ++----- Diablo.dsw | 15 ++++++ DiabloUI/DiabloUI.dsp | 6 ++- MakefileVC | 12 ++--- 6 files changed, 187 insertions(+), 23 deletions(-) create mode 100644 3rdParty/PKWare/Makefile create mode 100644 3rdParty/PKWare/Pkware.dsp diff --git a/3rdParty/PKWare/Makefile b/3rdParty/PKWare/Makefile new file mode 100644 index 000000000..377b29a23 --- /dev/null +++ b/3rdParty/PKWare/Makefile @@ -0,0 +1,59 @@ +VC5_DIR ?= $(HOME)/DevStudio_5.10/VC + +# The $(VS6_DIR) directory is a copy of the "Microsoft Visual Studio" directory. +# +# To get a working setup on Linux or other "portable" copies of VS, +# the following DLLs have to be copied to the +# $(VS6_DIR)/VC98/Bin directory. +# +# - $(VS6_DIR)/Common/MSDev98/Bin/MSPDB60.DLL +# +# And to the $(VC5_DIR)/bin directory. +# +# - $(VC5_DIR)/SharedIDE/bin/MSDIS100.DLL +# - $(VC5_DIR)/SharedIDE/bin/MSPDB50.DLL +VS6_DIR ?= $(HOME)/VS6 + +VC6_DIR = $(VS6_DIR)/VC98 + +VC6_BIN_DIR = $(VC6_DIR)/Bin +VC6_INC_DIR = $(VC6_DIR)/Include +VC6_LIB_DIR = $(VC6_DIR)/Lib + +VC5_LIB_DIR = $(VC5_DIR)/lib + +IDE_DIR ?= $(VS6_DIR)/Common/MSDev98 +IDE_BIN_DIR = $(IDE_DIR)/bin +ifeq ($(OS),Windows_NT) + CL = $(VC6_BIN_DIR)/CL.EXE + RC = $(IDE_BIN_DIR)/RC.EXE + VC5_LINK = $(VC5_DIR)/bin/link.exe + VC6_LINK = $(VC6_BIN_DIR)/link.exe +else + CL = wine $(VC6_BIN_DIR)/CL.EXE + RC = wine $(IDE_BIN_DIR)/RC.EXE + VC5_LINK = wine $(VC5_DIR)/bin/link.exe + VC6_LINK = wine $(VC6_BIN_DIR)/link.exe +endif + +CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /FD /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /Gm /Zi +LINKFLAGS=/nologo /subsystem:windows /machine:I386 /incremental:no + +VC_LINK=$(VC5_LINK) +LINKFLAGS+= /LIBPATH:$(VC5_LIB_DIR) + +all: pkware.lib + +PKWARE_SRC=$(sort $(wildcard *.cpp)) +PKWARE_OBJS=$(PKWARE_SRC:.cpp=.obj) + +pkware.lib: $(PKWARE_OBJS) + $(VC_LINK) -lib /OUT:$@ $^ /nologo + +%.obj: %.cpp + $(CL) $(CFLAGS) /Fo$@ $< + +clean: + @$(RM) -v $(PKWARE_OBJS) pkware.lib vc60.{idb,pch,pdb} + +.PHONY: clean all diff --git a/3rdParty/PKWare/Pkware.dsp b/3rdParty/PKWare/Pkware.dsp new file mode 100644 index 000000000..f3bdc2239 --- /dev/null +++ b/3rdParty/PKWare/Pkware.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="Pkware" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=Pkware - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "Pkware.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "Pkware.mak" CFG="Pkware - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Pkware - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "Pkware - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Pkware - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "WinRel" +# PROP BASE Intermediate_Dir "WinRel" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "WinRel" +# PROP Intermediate_Dir "WinRel" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "Pkware - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "WinDebug" +# PROP BASE Intermediate_Dir "WinDebug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "WinDebug" +# PROP Intermediate_Dir "WinDebug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "Pkware - Win32 Release" +# Name "Pkware - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\explode.cpp +# End Source File +# Begin Source File + +SOURCE=.\implode.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# End Target +# End Project diff --git a/Diablo.dsp b/Diablo.dsp index 8c96715d7..1e9cbf321 100644 --- a/Diablo.dsp +++ b/Diablo.dsp @@ -54,7 +54,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 DiabloUI/WinRel/DiabloUI.lib 3rdParty/Storm/Source/WinRel/Storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib /nologo /subsystem:windows /machine:I386 !ELSEIF "$(CFG)" == "Diablo - Win32 Debug" @@ -107,8 +107,8 @@ BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe -# ADD BASE LINK32 DiabloUI/WinRel/DiabloUI.lib 3rdParty/Storm/Source/WinRel/Storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 DiabloUI/WinRel/DiabloUI.lib 3rdParty/Storm/Source/WinRel/Storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib /nologo /subsystem:windows /debug /machine:I386 +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 DiabloUI/WinRel/diabloui.lib 3rdParty/Storm/Source/WinRel/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib 3rdParty/PKWare/WinRel/pkware.lib /nologo /subsystem:windows /debug /machine:I386 !ENDIF @@ -722,17 +722,5 @@ SOURCE=.\Source\wave.h SOURCE=.\resource.h # End Source File # End Group -# Begin Group "PKWare" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\3rdParty\PKWare\explode.cpp -# End Source File -# Begin Source File - -SOURCE=.\3rdParty\PKWare\implode.cpp -# End Source File -# End Group # End Target # End Project diff --git a/Diablo.dsw b/Diablo.dsw index 06b9cb92a..e456f707c 100644 --- a/Diablo.dsw +++ b/Diablo.dsw @@ -17,6 +17,9 @@ Package=<4> Begin Project Dependency Project_Dep_Name Storm End Project Dependency + Begin Project Dependency + Project_Dep_Name Pkware + End Project Dependency }}} ############################################################################### @@ -36,6 +39,18 @@ Package=<4> ############################################################################### +Project: "Pkware"=".\3rdParty\PKWare\Pkware.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + Project: "Storm"=".\3rdParty\Storm\Source\Storm.dsp" - Package Owner=<4> Package=<5> diff --git a/DiabloUI/DiabloUI.dsp b/DiabloUI/DiabloUI.dsp index 99817473a..18ed22542 100644 --- a/DiabloUI/DiabloUI.dsp +++ b/DiabloUI/DiabloUI.dsp @@ -40,6 +40,7 @@ RSC=rc.exe # PROP Use_Debug_Libraries 0 # PROP Output_Dir "WinRel" # PROP Intermediate_Dir "WinRel" +# PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c @@ -52,7 +53,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 -# ADD LINK32 ../3rdParty/Storm/Source/WinRel/Storm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /def:"diabloui.def" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /def:"diabloui.def" !ELSEIF "$(CFG)" == "DiabloUI - Win32 Debug" @@ -65,6 +66,7 @@ LINK32=link.exe # PROP Use_Debug_Libraries 1 # PROP Output_Dir "WinDebug" # PROP Intermediate_Dir "WinDebug" +# PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /O1 /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c @@ -77,7 +79,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 ../3rdParty/Storm/Source/WinDebug/Storm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /def:"diabloui.def" /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /def:"diabloui.def" /pdbtype:sept !ENDIF diff --git a/MakefileVC b/MakefileVC index ee5a266cc..655b1da24 100644 --- a/MakefileVC +++ b/MakefileVC @@ -57,11 +57,8 @@ DIABLO_SRC=$(sort $(filter-out Source/_asm.cpp Source/_render.cpp Source/render. DIABLO_SRC += Source/render.cpp OBJS=$(DIABLO_SRC:.cpp=.obj) -PKWARE_SRC=$(sort $(wildcard 3rdParty/PKWare/*.cpp)) -PKWARE_OBJS=$(PKWARE_SRC:.cpp=.obj) - -Diablo.exe: main_files $(PKWARE_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib - $(VC_LINK) /OUT:$@ $(LINKFLAGS) $(OBJS) $(PKWARE_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib +Diablo.exe: main_files diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib 3rdParty/PKWare/pkware.lib + $(VC_LINK) /OUT:$@ $(LINKFLAGS) $(OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib 3rdParty/PKWare/pkware.lib DiabloUI/diabloui.lib: make -C DiabloUI @@ -69,6 +66,9 @@ DiabloUI/diabloui.lib: 3rdParty/Storm/storm.lib: make -C 3rdParty/Storm +3rdParty/PKWare/pkware.lib: + make -C 3rdParty/PKWare + # compiles all main source files with once compiler call main_files: $(CL) $(CFLAGS) /FoSource/ $(DIABLO_SRC) @@ -80,6 +80,6 @@ diablo.res: Diablo.rc $(RC) /i $(VC6_INC_DIR) /i $(VC6_DIR)/MFC/Include /l 0x409 /fo $@ $< clean: - @$(RM) -v $(OBJS) $(PKWARE_OBJS) + @$(RM) -v $(OBJS) .PHONY: clean all From faeb360c88bcf59b1c3219144bde89e9e88b0db8 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 9 May 2019 00:32:25 +0200 Subject: [PATCH 33/37] Revert multi.h to not include storm.h --- 3rdParty/Storm/Source/storm.h | 7 ------- Source/multi.cpp | 1 + Source/multi.h | 2 -- structs.h | 7 +++++++ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/3rdParty/Storm/Source/storm.h b/3rdParty/Storm/Source/storm.h index c66f36752..751d22b32 100644 --- a/3rdParty/Storm/Source/storm.h +++ b/3rdParty/Storm/Source/storm.h @@ -372,13 +372,6 @@ typedef struct _s_evt DWORD dwSize; } S_EVT, *PS_EVT; -typedef struct _SNETEVENT { - int eventid; - int playerid; - void *data; - int databytes; -} _SNETEVENT; - typedef void (STORMAPI *SEVTHANDLER)(struct _SNETEVENT *); // @TODO: "type" is unknown. diff --git a/Source/multi.cpp b/Source/multi.cpp index 6e1eb5cf1..8bbca9fd6 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -1,4 +1,5 @@ #include "diablo.h" +#include "../3rdParty/Storm/Source/storm.h" #include "../DiabloUI/diabloui.h" BOOLEAN gbSomebodyWonGameKludge; // weak diff --git a/Source/multi.h b/Source/multi.h index 142ae8268..26330aa5f 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -2,8 +2,6 @@ #ifndef __MULTI_H__ #define __MULTI_H__ -#include "../3rdParty/Storm/Source/storm.h" - extern BOOLEAN gbSomebodyWonGameKludge; // weak extern char szPlayerDescript[128]; extern WORD sgwPackPlrOffsetTbl[MAX_PLRS]; diff --git a/structs.h b/structs.h index 09299c300..9a1a1854c 100644 --- a/structs.h +++ b/structs.h @@ -1262,6 +1262,13 @@ typedef struct _SNETCAPS { int defaultturnsintransit; } _SNETCAPS; +typedef struct _SNETEVENT { + int eventid; + int playerid; + void *data; + int databytes; +} _SNETEVENT; + // TPDEF PTR FCN UCHAR SNETABORTPROC // TPDEF PTR FCN UCHAR SNETCATEGORYPROC // TPDEF PTR FCN UCHAR SNETCHECKAUTHPROC From 47f747a560ab7575ded2b45df090c23c74806d8a Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Thu, 9 May 2019 01:33:13 +0300 Subject: [PATCH 34/37] Clean up MAI_Sneak. --- Source/monster.cpp | 103 ++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 63 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index ec197fc0c..b4708a5d4 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3263,87 +3263,64 @@ void MAI_Fat(int i) void MAI_Sneak(int i) { - int v1; // edi - MonsterStruct *v2; // esi - int v3; // ebx - int v4; // ebx - int v6; // edi - int v7; // eax - //int v8; // ST04_4 - int v9; // eax - //int v10; // ST04_4 - int v11; // eax - int v12; // edi - signed int v13; // ecx - int v14; // eax - int v15; // [esp+Ch] [ebp-10h] - int arglist; // [esp+10h] [ebp-Ch] - int v17; // [esp+14h] [ebp-8h] - int md; // [esp+18h] [ebp-4h] + MonsterStruct *Monst; + int mx, my, md; + int dist, v; - v1 = i; - arglist = i; if ((DWORD)i >= MAXMONSTERS) { app_fatal("MAI_Sneak: Invalid monster %d", i); } - v2 = &monster[v1]; - if (v2->_mmode == MM_STAND) { - v3 = v2->_my; - if (dLight[v2->_mx][v3] != lightmax) { - v17 = v2->_mx - (unsigned char)v2->_menemyx; - v4 = v3 - (unsigned char)v2->_menemyy; - md = M_GetDir(v1); - v6 = 5 - (unsigned char)v2->_mint; - if (v2->_mVar1 == MM_GOTHIT) { - v2->_mgoalvar1 = 0; - _LOBYTE(v2->_mgoal) = MGOAL_RETREAT; + Monst = monster + i; + if (Monst->_mmode == MM_STAND) { + mx = Monst->_mx; + my = Monst->_my; + if (dLight[mx][my] != lightmax) { + mx -= Monst->_menemyx; + my -= Monst->_menemyy; + + md = M_GetDir(i); + dist = 5 - Monst->_mint; + if (Monst->_mVar1 == MM_GOTHIT) { + Monst->_mgoalvar1 = 0; + Monst->_mgoal = MGOAL_RETREAT; } else { - v7 = abs(v17); - //v5 = v8; - if (v7 >= v6 + 3 || (v9 = abs(v4), v9 >= v6 + 3) || v2->_mgoalvar1 > 8) /* v5 = v10, */ - { - v2->_mgoalvar1 = 0; - _LOBYTE(v2->_mgoal) = MGOAL_NORMAL; + if (abs(mx) >= dist + 3 || abs(my) >= dist + 3 || Monst->_mgoalvar1 > 8) { + Monst->_mgoalvar1 = 0; + Monst->_mgoal = MGOAL_NORMAL; } } - if (_LOBYTE(v2->_mgoal) == MGOAL_RETREAT) { - if (v2->_mFlags & MFLAG_TARGETS_MONSTER) - md = GetDirection(v2->_mx, v2->_my, plr[v2->_menemy]._pownerx, plr[v2->_menemy]._pownery); + if (Monst->_mgoal == MGOAL_RETREAT) { + if (Monst->_mFlags & MFLAG_TARGETS_MONSTER) + md = GetDirection(Monst->_mx, Monst->_my, plr[Monst->_menemy]._pownerx, plr[Monst->_menemy]._pownery); md = opposite[md]; - if (v2->MType->mtype == MT_UNSEEN) { + if (Monst->MType->mtype == MT_UNSEEN) { if (random(112, 2)) - v11 = left[md]; + md = left[md]; else - v11 = right[md]; - md = v11; + md = right[md]; } } - v2->_mdir = md; - v15 = random(112, 100); - if (abs(v17) < v6 && abs(v4) < v6 && v2->_mFlags & MFLAG_HIDDEN) { - M_StartFadein(arglist, md, FALSE); + Monst->_mdir = md; + v = random(112, 100); + if (abs(mx) < dist && abs(my) < dist && Monst->_mFlags & MFLAG_HIDDEN) { + M_StartFadein(i, md, FALSE); } else { - v12 = v6 + 1; - if (abs(v17) < v12 && abs(v4) < v12 || v2->_mFlags & MFLAG_HIDDEN) { - if (_LOBYTE(v2->_mgoal) == MGOAL_RETREAT - || (abs(v17) >= 2 || abs(v4) >= 2) - && ((v13 = v2->_mVar2, v13 > 20) && v15 < 4 * (unsigned char)v2->_mint + 14 - || ((v14 = v2->_mVar1, v14 == MM_WALK) || v14 == MM_WALK2 || v14 == MM_WALK3) - && !v13 - && v15 < 4 * (unsigned char)v2->_mint + 64)) { - ++v2->_mgoalvar1; - M_CallWalk(arglist, md); - } + if ((abs(mx) >= dist + 1 || abs(my) >= dist + 1) && !(Monst->_mFlags & MFLAG_HIDDEN)) { + M_StartFadeout(i, md, TRUE); } else { - M_StartFadeout(arglist, md, TRUE); + if (Monst->_mgoal == MGOAL_RETREAT + || (abs(mx) >= 2 || abs(my) >= 2) && (Monst->_mVar2 > 20 && v < 4 * Monst->_mint + 14 || (Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) && Monst->_mVar2 == 0 && v < 4 * Monst->_mint + 64)) { + Monst->_mgoalvar1++; + M_CallWalk(i, md); + } } } - if (v2->_mmode == MM_STAND) { - if (abs(v17) >= 2 || abs(v4) >= 2 || v15 >= 4 * (unsigned char)v2->_mint + 10) - v2->_mAnimData = v2->MType->Anims[MA_STAND].Data[md]; + if (Monst->_mmode == MM_STAND) { + if (abs(mx) >= 2 || abs(my) >= 2 || v >= 4 * Monst->_mint + 10) + Monst->_mAnimData = Monst->MType->Anims[MA_STAND].Data[md]; else - M_StartAttack(arglist); + M_StartAttack(i); } } } From 65ad296de43a0cfa0e65de2b9ae6827385679233 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Wed, 8 May 2019 22:45:12 -0500 Subject: [PATCH 35/37] Bugfix note to M2MStartKill --- Source/monster.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/monster.cpp b/Source/monster.cpp index b4708a5d4..4f7e17972 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -1696,6 +1696,8 @@ void M2MStartKill(int i, int mid) if ((DWORD)i >= MAXMONSTERS) { app_fatal("M2MStartKill: Invalid monster (attacker) %d", i); + } + if ((DWORD)i >= MAXMONSTERS) { /// BUGFIX: should check `mid` app_fatal("M2MStartKill: Invalid monster (killed) %d", mid); } if (!monster[i].MType) From 6cac36f4db20a1c948e044021ee38e42a7227ba1 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Thu, 9 May 2019 15:06:24 +0300 Subject: [PATCH 36/37] Clean up MAI_Round. --- Source/monster.cpp | 138 ++++++++++++++------------------------------- 1 file changed, 43 insertions(+), 95 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 4f7e17972..464a87759 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3494,112 +3494,60 @@ void MAI_Cleaver(int i) void MAI_Round(int i, BOOL special) { - int v2; // esi - MonsterStruct *v3; // esi - int v4; // edx - int v5; // ecx - int v6; // edi - int v7; // ebx - int v9; // eax - //int v10; // ST04_4 - int v12; // eax - //int v13; // ST04_4 - int v15; // edi - int v16; // eax - int v17; // ecx - BOOLEAN v18; // eax - //int v19; // eax - int v21; // eax - int v22; // eax - //int v23; // ST04_4 - signed int v25; // ecx - int v26; // eax - int v27; // [esp+4h] [ebp-18h] - int v28; // [esp+8h] [ebp-14h] - char *v29; // [esp+8h] [ebp-14h] - int v30; // [esp+Ch] [ebp-10h] - int md; // [esp+10h] [ebp-Ch] - int v32; // [esp+14h] [ebp-8h] - int arglist; // [esp+18h] [ebp-4h] + MonsterStruct *Monst; + int fx, fy; + int mx, my, md; + int dist, v; - v2 = i; - v27 = special; - arglist = i; if ((DWORD)i >= MAXMONSTERS) app_fatal("MAI_Round: Invalid monster %d", i); - v3 = &monster[v2]; - if (v3->_mmode == MM_STAND && v3->_msquelch) { - v4 = v3->_my; - v5 = v3->_mx; - v28 = (unsigned char)v3->_menemyy; - v6 = (unsigned char)v3->_menemyx; - v7 = v5 - v6; - v32 = v4 - v28; - md = GetDirection(v5, v4, v3->_lastx, v3->_lasty); - if (v3->_msquelch < 0xFFu) /* check sign */ - MonstCheckDoors(arglist); - v30 = random(114, 100); - if ((abs(v7) >= 2 || abs(v32) >= 2) && v3->_msquelch == -1) { - v29 = &dTransVal[v6][v28]; - if (dTransVal[v3->_mx][v3->_my] == *v29) { - if (_LOBYTE(v3->_mgoal) != MGOAL_MOVE) { - v9 = abs(v7); - //v11 = v10; - if (v9 < 4) { - v12 = abs(v32); - //v11 = v13; - if (v12 < 4) - goto LABEL_26; - } - if (random(115, 4)) - goto LABEL_26; - if (_LOBYTE(v3->_mgoal) != MGOAL_MOVE) { - v3->_mgoalvar1 = 0; - v3->_mgoalvar2 = random(116, 2); - } + Monst = monster + i; + if (Monst->_mmode == MM_STAND && Monst->_msquelch) { + fy = Monst->_menemyy; + fx = Monst->_menemyx; + mx = Monst->_mx - fx; + my = Monst->_my - fy; + md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); + if ((BYTE)Monst->_msquelch < 255) + MonstCheckDoors(i); + v = random(114, 100); + if ((abs(mx) >= 2 || abs(my) >= 2) && Monst->_msquelch == -1 && dTransVal[Monst->_mx][Monst->_my] == dTransVal[fx][fy]) { + if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 4 || abs(my) >= 4) && random(115, 4) == 0) { + if (Monst->_mgoal != MGOAL_MOVE) { + Monst->_mgoalvar1 = 0; + Monst->_mgoalvar2 = random(116, 2); } - _LOBYTE(v3->_mgoal) = MGOAL_MOVE; - v15 = abs(v32); - if (abs(v7) <= v15) - v16 = abs(v32); + Monst->_mgoal = MGOAL_MOVE; + if (abs(mx) > abs(my)) + dist = abs(mx); else - v16 = abs(v7); - v17 = v3->_mgoalvar1; - v3->_mgoalvar1 = v17 + 1; - if (v17 < 2 * v16 || (v18 = DirOK(arglist, md), !v18)) { - if (dTransVal[v3->_mx][v3->_my] == *v29) { - //_LOBYTE(v19) = M_RoundWalk(arglist, md, &v3->_mgoalvar2); - if (!M_RoundWalk(arglist, md, &v3->_mgoalvar2)) { - v21 = random(125, 10); - M_StartDelay(arglist, v21 + 10); - } - goto LABEL_26; - } + dist = abs(my); + if (Monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md) || dTransVal[Monst->_mx][Monst->_my] != dTransVal[fx][fy]) { + Monst->_mgoal = MGOAL_NORMAL; + } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { + M_StartDelay(i, random(125, 10) + 10); } } - } - _LOBYTE(v3->_mgoal) = MGOAL_NORMAL; - LABEL_26: - if (_LOBYTE(v3->_mgoal) == MGOAL_NORMAL) { - if (abs(v7) >= 2 || (v22 = abs(v32), v22 >= 2)) /* v24 = v23, */ - { - v25 = v3->_mVar2; - if (v25 > 20 && v30 < 2 * (unsigned char)v3->_mint + 28 - || ((v26 = v3->_mVar1, v26 == MM_WALK) || v26 == MM_WALK2 || v26 == MM_WALK3) - && !v25 - && v30 < 2 * (unsigned char)v3->_mint + 78) { - M_CallWalk(arglist, md); + } else + Monst->_mgoal = MGOAL_NORMAL; + if (Monst->_mgoal == MGOAL_NORMAL) { + if (abs(mx) >= 2 || abs(my) >= 2) { + if (Monst->_mVar2 > 20 && v < 2 * Monst->_mint + 28 + || (Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) + && Monst->_mVar2 == 0 + && v < 2 * Monst->_mint + 78) { + M_CallWalk(i, md); } - } else if (v30 < 2 * (unsigned char)v3->_mint + 23) { - v3->_mdir = md; - if (v27 && v3->_mhitpoints_mmaxhp>> 1 && random(117, 2)) - M_StartSpAttack(arglist); + } else if (v < 2 * Monst->_mint + 23) { + Monst->_mdir = md; + if (special && Monst->_mhitpoints < (Monst->_mmaxhp >> 1) && random(117, 2) != 0) + M_StartSpAttack(i); else - M_StartAttack(arglist); + M_StartAttack(i); } } - if (v3->_mmode == MM_STAND) - v3->_mAnimData = v3->MType->Anims[MA_STAND].Data[md]; + if (Monst->_mmode == MM_STAND) + Monst->_mAnimData = Monst->MType->Anims[MA_STAND].Data[md]; } } From 50bb72635354215ef836c4bb0deceb85d43c34fb Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Thu, 9 May 2019 19:06:35 +0300 Subject: [PATCH 37/37] Clean up MAI_Scav. --- Source/monster.cpp | 195 +++++++++++++++++---------------------------- 1 file changed, 74 insertions(+), 121 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 464a87759..d25c63437 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3618,138 +3618,91 @@ void MAI_AcidUniq(int i) void MAI_Scav(int i) { - int v1; // edi - int v2; // esi - unsigned char *v3; // eax - int v4; // ecx - int v5; // ecx - signed int v6; // ebx - signed int v7; // edi - int v8; // edx - int v9; // eax - BOOLEAN v10; // eax - int v11; // ebx - int v12; // edi - signed int v13; // edi - int v14; // edx - int v15; // eax - BOOLEAN v16; // eax - int v17; // eax - int v18; // eax - int arglist; // [esp+Ch] [ebp-8h] - BOOL v20; // [esp+10h] [ebp-4h] + BOOL done; + int x, y; + int _mx, _my; + MonsterStruct *Monst; + int _goalvar1; - v1 = i; - arglist = i; if ((DWORD)i >= MAXMONSTERS) app_fatal("MAI_Scav: Invalid monster %d", i); - v2 = v1; - v20 = 0; - if (monster[v1]._mmode == MM_STAND) { - if (monster[v2]._mhitpoints> 1) { - if (_LOBYTE(monster[v2]._mgoal) == MGOAL_HEALING) - goto LABEL_10; - if (monster[v2].leaderflag) { - v3 = &monster[(unsigned char)monster[v2].leader].packsize; - --*v3; - monster[v2].leaderflag = 0; + Monst = monster + i; + _mx = Monst->_mx; + _my = Monst->_my; + done = FALSE; + if (monster[i]._mmode != MM_STAND) + return; + if (Monst->_mhitpoints < (Monst->_mmaxhp >> 1) && Monst->_mgoal != MGOAL_HEALING) { + if (Monst->leaderflag) { + monster[Monst->leader].packsize--; + Monst->leaderflag = 0; + } + Monst->_mgoal = MGOAL_HEALING; + Monst->_mgoalvar3 = 10; + } + if (Monst->_mgoal == MGOAL_HEALING && Monst->_mgoalvar3 != 0) { + Monst->_mgoalvar3--; + if (dDead[Monst->_mx][Monst->_my]) { + M_StartEat(i); + if (!(Monst->_mFlags & MFLAG_NOHEAL)) + Monst->_mhitpoints += 64; + if (Monst->_mhitpoints >= (Monst->_mmaxhp >> 1) + (Monst->_mmaxhp >> 2)) { + Monst->_mgoal = MGOAL_NORMAL; + Monst->_mgoalvar1 = 0; + Monst->_mgoalvar2 = 0; } - _LOBYTE(monster[v2]._mgoal) = MGOAL_HEALING; - monster[v2]._mgoalvar3 = 10; - } - if (_LOBYTE(monster[v2]._mgoal) != MGOAL_HEALING) { - LABEL_52: - if (monster[v2]._mmode == MM_STAND) - MAI_SkelSd(arglist); - return; - } - LABEL_10: - v4 = monster[v2]._mgoalvar3; - if (v4) { - monster[v2]._mgoalvar3 = v4 - 1; - v5 = monster[v2]._my; - if (dDead[monster[v2]._mx][v5]) { - M_StartEat(v1); - if (!(monster[v2]._mFlags & MFLAG_NOHEAL)) - monster[v2]._mhitpoints += 64; - if (monster[v2]._mhitpoints >= (monster[v2]._mmaxhp >> 1) + (monster[v2]._mmaxhp >> 2)) { - _LOBYTE(monster[v2]._mgoal) = MGOAL_NORMAL; - monster[v2]._mgoalvar1 = 0; - monster[v2]._mgoalvar2 = 0; - } - } else { - if (!monster[v2]._mgoalvar1) { - v6 = arglist; - if (random(120, 2)) { - v7 = -4; - do { - if (v20) - break; - v6 = -4; - do { - if (v20) - break; - if (v7 >= 0 && v7 < MAXDUNY && v6 >= 0 && v6 < MAXDUNX) { - v8 = monster[v2]._mx; - v9 = monster[v2]._my; - v20 = dDead[v8 + v6][v9 + v7] - && (v10 = LineClearF( - CheckNoSolid, - v8, - v9, - v8 + v6, - v9 + v7), - v10); - } - ++v6; - } while (v6 <= 4); - ++v7; - } while (v7 <= 4); - v11 = v6 - 1; - v12 = v7 - 1; - } else { - v13 = 4; - do { - if (v20) - break; - v6 = 4; - do { - if (v20) - break; - if (v13 >= 0 && v13 < MAXDUNY && v6 >= 0 && v6 < MAXDUNX) { - v14 = monster[v2]._mx; - v15 = monster[v2]._my; - v20 = dDead[v14 + v6][v15 + v13] - && (v16 = LineClearF( - CheckNoSolid, - v14, - v15, - v14 + v6, - v15 + v13), - v16); - } - --v6; - } while (v6 >= -4); - --v13; - } while (v13 >= -4); - v11 = v6 + 1; - v12 = v13 + 1; + } else { + if (Monst->_mgoalvar1 == 0) { + if (random(120, 2) != 0) { + for (y = -4; y <= 4 && !done; y++) { + for (x = -4; x <= 4 && !done; x++) { + // BUGFIX: incorrect check of offset against limits of the dungeon + if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX) + continue; + done = dDead[Monst->_mx + x][Monst->_my + y] != 0 + && LineClearF( + CheckNoSolid, + Monst->_mx, + Monst->_my, + Monst->_mx + x, + Monst->_my + y); + } } - if (v20) { - monster[v2]._mgoalvar1 = monster[v2]._mx + v11 + 1; - monster[v2]._mgoalvar2 = monster[v2]._my + v12 + 1; + x--; + y--; + } else { + for (y = 4; y >= -4 && !done; y--) { + for (x = 4; x >= -4 && !done; x--) { + // BUGFIX: incorrect check of offset against limits of the dungeon + if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX) + continue; + done = dDead[Monst->_mx + x][Monst->_my + y] != 0 + && LineClearF( + CheckNoSolid, + Monst->_mx, + Monst->_my, + Monst->_mx + x, + Monst->_my + y); + } } + x++; + y++; } - v17 = monster[v2]._mgoalvar1; - if (v17) { - v18 = GetDirection(monster[v2]._mx, monster[v2]._my, v17 - 1, monster[v2]._mgoalvar2 - 1); - monster[v2]._mdir = v18; - M_CallWalk(arglist, v18); + if (done) { + Monst->_mgoalvar1 = x + Monst->_mx + 1; + Monst->_mgoalvar2 = y + Monst->_my + 1; } } + if (Monst->_mgoalvar1) { + x = Monst->_mgoalvar1 - 1; + y = Monst->_mgoalvar2 - 1; + Monst->_mdir = GetDirection(Monst->_mx, Monst->_my, x, y); + M_CallWalk(i, Monst->_mdir); + } } - goto LABEL_52; } + if (Monst->_mmode == MM_STAND) + MAI_SkelSd(i); } void MAI_Garg(int i)