diff --git a/Source/appfat.cpp b/Source/appfat.cpp index 5022f3e5c..7d557cbed 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -16,32 +16,12 @@ BOOL terminating; /** Thread id of the last callee to FreeDlg(). */ SDL_threadID cleanup_thread_id; -/** - * @brief Terminates the game and displays an error message box. - * @param pszFmt Optional error message. - * @param ... (see printf) - */ -void app_fatal(const char *pszFmt, ...) -{ - va_list va; - - va_start(va, pszFmt); - FreeDlg(); - - if (pszFmt) - MsgBox(pszFmt, va); - - va_end(va); - - diablo_quit(1); -} - /** * @brief Displays an error message box based on the given format string and variable argument list. * @param pszFmt Error message format * @param va Additional parameters for message format */ -void MsgBox(const char *pszFmt, va_list va) +static void MsgBox(const char *pszFmt, va_list va) { char text[256]; @@ -53,7 +33,7 @@ void MsgBox(const char *pszFmt, va_list va) /** * @brief Cleans up after a fatal application error. */ -void FreeDlg() +static void FreeDlg() { if (terminating && cleanup_thread_id != SDL_GetThreadID(NULL)) SDL_Delay(20000); @@ -69,6 +49,26 @@ void FreeDlg() SNetDestroy(); } +/** + * @brief Terminates the game and displays an error message box. + * @param pszFmt Optional error message. + * @param ... (see printf) + */ +void app_fatal(const char *pszFmt, ...) +{ + va_list va; + + va_start(va, pszFmt); + FreeDlg(); + + if (pszFmt) + MsgBox(pszFmt, va); + + va_end(va); + + diablo_quit(1); +} + /** * @brief Displays a warning message box based on the given formatted error message. * @param pszFmt Error message format diff --git a/Source/appfat.h b/Source/appfat.h index c12f62538..8116c2c59 100644 --- a/Source/appfat.h +++ b/Source/appfat.h @@ -12,24 +12,16 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -extern char sz_error_buf[256]; -extern BOOL terminating; - void TriggerBreak(); -char *GetErrorStr(DWORD error_code); #define TraceLastError SDL_GetError void app_fatal(const char *pszFmt, ...); -void MsgBox(const char *pszFmt, va_list va); -void FreeDlg(); void DrawDlg(const char *pszFmt, ...); #ifdef _DEBUG void assert_fail(int nLineNo, const char *pszFile, const char *pszFail); #endif void DDErrMsg(DWORD error_code, int log_line_nr, const char *log_file_path); void DSErrMsg(DWORD error_code, int log_line_nr, const char *log_file_path); -void center_window(HWND hDlg); void ErrDlg(const char *title, const char *error, const char *log_file_path, int log_line_nr); -void TextDlg(HWND hDlg, char *text); void FileErrDlg(const char *error); void DiskFreeDlg(const char *error); void InsertCDDlg(); diff --git a/Source/automap.cpp b/Source/automap.cpp index ae8e89822..9b734e22e 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -203,111 +203,10 @@ void AutomapZoomOut() } } -/** - * @brief Renders the automap on screen. - */ -void DrawAutomap() -{ - int cells; - int sx, sy; - int i, j, d; - int mapx, mapy; - - if (leveltype == DTYPE_TOWN) { - DrawAutomapText(); - return; - } - - gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_Y + VIEWPORT_HEIGHT)]; - - AutoMapX = (ViewX - 16) >> 1; - while (AutoMapX + AutoMapXOfs < 0) - AutoMapXOfs++; - while (AutoMapX + AutoMapXOfs >= DMAXX) - AutoMapXOfs--; - AutoMapX += AutoMapXOfs; - - AutoMapY = (ViewY - 16) >> 1; - while (AutoMapY + AutoMapYOfs < 0) - AutoMapYOfs++; - while (AutoMapY + AutoMapYOfs >= DMAXY) - AutoMapYOfs--; - AutoMapY += AutoMapYOfs; - - d = (AutoMapScale << 6) / 100; - cells = 2 * (SCREEN_WIDTH / 2 / d) + 1; - if ((SCREEN_WIDTH / 2) % d) - cells++; - if ((SCREEN_WIDTH / 2) % d >= (AutoMapScale << 5) / 100) - cells++; - - if (ScrollInfo._sxoff + ScrollInfo._syoff) - cells++; - mapx = AutoMapX - cells; - mapy = AutoMapY - 1; - - if (cells & 1) { - sx = SCREEN_WIDTH / 2 + SCREEN_X - AmLine64 * ((cells - 1) >> 1); - sy = (SCREEN_HEIGHT - PANEL_HEIGHT) / 2 + SCREEN_Y - AmLine32 * ((cells + 1) >> 1); - } else { - sx = SCREEN_WIDTH / 2 + SCREEN_X - AmLine64 * (cells >> 1) + AmLine32; - sy = (SCREEN_HEIGHT - PANEL_HEIGHT) / 2 + SCREEN_Y - AmLine32 * (cells >> 1) - AmLine16; - } - if (ViewX & 1) { - sx -= AmLine16; - sy -= AmLine8; - } - if (ViewY & 1) { - sx += AmLine16; - sy -= AmLine8; - } - - sx += AutoMapScale * ScrollInfo._sxoff / 100 >> 1; - sy += AutoMapScale * ScrollInfo._syoff / 100 >> 1; - if (PANELS_COVER) { - if (invflag || sbookflag) { - sx -= SCREEN_WIDTH / 4; - } - if (chrflag || questlog) { - sx += SCREEN_WIDTH / 4; - } - } - - for (i = 0; i <= cells + 1; i++) { - int x = sx; - int y; - - for (j = 0; j < cells; j++) { - WORD maptype = GetAutomapType(mapx + j, mapy - j, TRUE); - if (maptype != 0) - DrawAutomapTile(x, sy, maptype); - x += AmLine64; - } - mapy++; - x = sx - AmLine32; - y = sy + AmLine16; - for (j = 0; j <= cells; j++) { - WORD maptype = GetAutomapType(mapx + j, mapy - j, TRUE); - if (maptype != 0) - DrawAutomapTile(x, y, maptype); - x += AmLine64; - } - mapx++; - sy += AmLine32; - } - DrawAutomapPlr(); -#ifdef HELLFIRE - if (AutoMapShowItems) - SearchAutomapItem(); -#endif - DrawAutomapText(); - gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_Y + SCREEN_HEIGHT)]; -} - /** * @brief Renders the given automap shape at the specified screen coordinates. */ -void DrawAutomapTile(int sx, int sy, WORD automap_type) +static void DrawAutomapTile(int sx, int sy, WORD automap_type) { BOOL do_vert; BOOL do_horz; @@ -491,7 +390,21 @@ void DrawAutomapTile(int sx, int sy, WORD automap_type) DrawLine(sx, sy + AmLine16, sx + AmLine32, sy, COLOR_DIM); } } + #ifdef HELLFIRE +static void DrawAutomapItem(int x, int y, BYTE color) +{ + int x1, y1, x2, y2; + + x1 = x - AmLine32 / 2; + y1 = y - AmLine16 / 2; + x2 = x1 + AmLine64 / 2; + y2 = y1 + AmLine32 / 2; + DrawLine(x, y1, x1, y, color); + DrawLine(x, y1, x2, y, color); + DrawLine(x, y2, x1, y, color); + DrawLine(x, y2, x2, y, color); +} void SearchAutomapItem() { @@ -557,26 +470,12 @@ void SearchAutomapItem() } } } - -void DrawAutomapItem(int x, int y, BYTE color) -{ - int x1, y1, x2, y2; - - x1 = x - AmLine32 / 2; - y1 = y - AmLine16 / 2; - x2 = x1 + AmLine64 / 2; - y2 = y1 + AmLine32 / 2; - DrawLine(x, y1, x1, y, color); - DrawLine(x, y1, x2, y, color); - DrawLine(x, y2, x1, y, color); - DrawLine(x, y2, x2, y, color); -} #endif /** * @brief Renders an arrow on the automap, centered on and facing the direction of the player. */ -void DrawAutomapPlr() +static void DrawAutomapPlr() { int px, py; int x, y; @@ -653,7 +552,7 @@ void DrawAutomapPlr() /** * @brief Returns the automap shape at the given coordinate. */ -WORD GetAutomapType(int x, int y, BOOL view) +static WORD GetAutomapType(int x, int y, BOOL view) { WORD rv; @@ -702,7 +601,7 @@ WORD GetAutomapType(int x, int y, BOOL view) /** * @brief Renders game info, such as the name of the current level, and in multi player the name of the game and the game password. */ -void DrawAutomapText() +static void DrawAutomapText() { char desc[256]; int nextline = 20; @@ -736,6 +635,107 @@ void DrawAutomapText() } } +/** + * @brief Renders the automap on screen. + */ +void DrawAutomap() +{ + int cells; + int sx, sy; + int i, j, d; + int mapx, mapy; + + if (leveltype == DTYPE_TOWN) { + DrawAutomapText(); + return; + } + + gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_Y + VIEWPORT_HEIGHT)]; + + AutoMapX = (ViewX - 16) >> 1; + while (AutoMapX + AutoMapXOfs < 0) + AutoMapXOfs++; + while (AutoMapX + AutoMapXOfs >= DMAXX) + AutoMapXOfs--; + AutoMapX += AutoMapXOfs; + + AutoMapY = (ViewY - 16) >> 1; + while (AutoMapY + AutoMapYOfs < 0) + AutoMapYOfs++; + while (AutoMapY + AutoMapYOfs >= DMAXY) + AutoMapYOfs--; + AutoMapY += AutoMapYOfs; + + d = (AutoMapScale << 6) / 100; + cells = 2 * (SCREEN_WIDTH / 2 / d) + 1; + if ((SCREEN_WIDTH / 2) % d) + cells++; + if ((SCREEN_WIDTH / 2) % d >= (AutoMapScale << 5) / 100) + cells++; + + if (ScrollInfo._sxoff + ScrollInfo._syoff) + cells++; + mapx = AutoMapX - cells; + mapy = AutoMapY - 1; + + if (cells & 1) { + sx = SCREEN_WIDTH / 2 + SCREEN_X - AmLine64 * ((cells - 1) >> 1); + sy = (SCREEN_HEIGHT - PANEL_HEIGHT) / 2 + SCREEN_Y - AmLine32 * ((cells + 1) >> 1); + } else { + sx = SCREEN_WIDTH / 2 + SCREEN_X - AmLine64 * (cells >> 1) + AmLine32; + sy = (SCREEN_HEIGHT - PANEL_HEIGHT) / 2 + SCREEN_Y - AmLine32 * (cells >> 1) - AmLine16; + } + if (ViewX & 1) { + sx -= AmLine16; + sy -= AmLine8; + } + if (ViewY & 1) { + sx += AmLine16; + sy -= AmLine8; + } + + sx += AutoMapScale * ScrollInfo._sxoff / 100 >> 1; + sy += AutoMapScale * ScrollInfo._syoff / 100 >> 1; + if (PANELS_COVER) { + if (invflag || sbookflag) { + sx -= SCREEN_WIDTH / 4; + } + if (chrflag || questlog) { + sx += SCREEN_WIDTH / 4; + } + } + + for (i = 0; i <= cells + 1; i++) { + int x = sx; + int y; + + for (j = 0; j < cells; j++) { + WORD maptype = GetAutomapType(mapx + j, mapy - j, TRUE); + if (maptype != 0) + DrawAutomapTile(x, sy, maptype); + x += AmLine64; + } + mapy++; + x = sx - AmLine32; + y = sy + AmLine16; + for (j = 0; j <= cells; j++) { + WORD maptype = GetAutomapType(mapx + j, mapy - j, TRUE); + if (maptype != 0) + DrawAutomapTile(x, y, maptype); + x += AmLine64; + } + mapx++; + sy += AmLine32; + } + DrawAutomapPlr(); +#ifdef HELLFIRE + if (AutoMapShowItems) + SearchAutomapItem(); +#endif + DrawAutomapText(); + gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_Y + SCREEN_HEIGHT)]; +} + /** * @brief Marks the given coordinate as within view on the automap. */ diff --git a/Source/automap.h b/Source/automap.h index d7b0b7601..bb145c04a 100644 --- a/Source/automap.h +++ b/Source/automap.h @@ -12,18 +12,11 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -extern WORD automaptype[512]; extern BOOL automapflag; -extern char AmShiftTab[32]; extern BOOLEAN automapview[DMAXX][DMAXY]; extern int AutoMapScale; extern int AutoMapXOfs; extern int AutoMapYOfs; -extern int AmLine64; -extern int AmLine32; -extern int AmLine16; -extern int AmLine8; -extern int AmLine4; void InitAutomapOnce(); void InitAutomap(); @@ -35,14 +28,6 @@ void AutomapRight(); void AutomapZoomIn(); void AutomapZoomOut(); void DrawAutomap(); -void DrawAutomapTile(int screen_x, int screen_y, WORD automap_type); -#ifdef HELLFIRE -void SearchAutomapItem(); -void DrawAutomapItem(int x, int y, BYTE color); -#endif -void DrawAutomapPlr(); -WORD GetAutomapType(int x, int y, BOOL view); -void DrawAutomapText(); void SetAutomapView(int x, int y); void AutomapZoomReset(); diff --git a/Source/codec.cpp b/Source/codec.cpp index c25929e8e..e8f682fb6 100644 --- a/Source/codec.cpp +++ b/Source/codec.cpp @@ -19,6 +19,38 @@ typedef struct CodecSignature { #define BLOCKSIZE 64 +static void codec_init_key(int unused, const char *pszPassword) +{ + char key[136]; // last 64 bytes are the SHA1 + uint32_t rand_state = 0x7058; + for (std::size_t i = 0; i < sizeof(key); ++i) { + rand_state = rand_state * 214013 + 2531011; + key[i] = rand_state >> 16; // Downcasting to char keeps the 2 least-significant bytes + } + + char pw[64]; + std::size_t password_i = 0; + for (std::size_t i = 0; i < sizeof(pw); ++i, ++password_i) { + if (pszPassword[password_i] == '\0') + password_i = 0; + pw[i] = pszPassword[password_i]; + } + + char digest[SHA1HashSize]; + SHA1Reset(0); + SHA1Calculate(0, pw, digest); + SHA1Clear(); + for (std::size_t i = 0; i < sizeof(key); ++i) + key[i] ^= digest[i % SHA1HashSize]; + memset(pw, 0, sizeof(pw)); + memset(digest, 0, sizeof(digest)); + for (int n = 0; n < 3; ++n) { + SHA1Reset(n); + SHA1Calculate(n, &key[72], NULL); + } + memset(key, 0, sizeof(key)); +} + int codec_decode(BYTE *pbSrcDst, DWORD size, const char *pszPassword) { char buf[128]; @@ -63,38 +95,6 @@ error: return 0; } -void codec_init_key(int unused, const char *pszPassword) -{ - char key[136]; // last 64 bytes are the SHA1 - uint32_t rand_state = 0x7058; - for (std::size_t i = 0; i < sizeof(key); ++i) { - rand_state = rand_state * 214013 + 2531011; - key[i] = rand_state >> 16; // Downcasting to char keeps the 2 least-significant bytes - } - - char pw[64]; - std::size_t password_i = 0; - for (std::size_t i = 0; i < sizeof(pw); ++i, ++password_i) { - if (pszPassword[password_i] == '\0') - password_i = 0; - pw[i] = pszPassword[password_i]; - } - - char digest[SHA1HashSize]; - SHA1Reset(0); - SHA1Calculate(0, pw, digest); - SHA1Clear(); - for (std::size_t i = 0; i < sizeof(key); ++i) - key[i] ^= digest[i % SHA1HashSize]; - memset(pw, 0, sizeof(pw)); - memset(digest, 0, sizeof(digest)); - for (int n = 0; n < 3; ++n) { - SHA1Reset(n); - SHA1Calculate(n, &key[72], NULL); - } - memset(key, 0, sizeof(key)); -} - DWORD codec_get_encoded_len(DWORD dwSrcBytes) { if (dwSrcBytes % BLOCKSIZE != 0) diff --git a/Source/codec.h b/Source/codec.h index a36984647..2c004f6be 100644 --- a/Source/codec.h +++ b/Source/codec.h @@ -13,7 +13,6 @@ extern "C" { #endif int codec_decode(BYTE *pbSrcDst, DWORD size, const char *pszPassword); -void codec_init_key(int unused, const char *pszPassword); DWORD codec_get_encoded_len(DWORD dwSrcBytes); void codec_encode(BYTE *pbSrcDst, DWORD size, int size_64, const char *pszPassword); diff --git a/Source/control.cpp b/Source/control.cpp index ffab7eb6d..9426ca8d3 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1268,6 +1268,58 @@ BOOL control_WriteStringToBuffer(BYTE *str) return TRUE; } +static void CPrintString(int y, const char *str, BOOL center, int lines) +{ + BYTE c; + const char *tmp; + int lineOffset, strWidth, sx, sy; + + lineOffset = 0; + sx = 177 + PANEL_X; + sy = lineOffsets[lines][y] + PANEL_Y; + if (center == TRUE) { + strWidth = 0; + tmp = str; + while (*tmp) { + c = gbFontTransTbl[(BYTE)*tmp++]; + strWidth += fontkern[fontframe[c]] + 2; + } + if (strWidth < 288) + lineOffset = (288 - strWidth) >> 1; + sx += lineOffset; + } + while (*str) { + c = gbFontTransTbl[(BYTE)*str++]; + c = fontframe[c]; + lineOffset += fontkern[c] + 2; + if (c) { + if (lineOffset < 288) { + PrintChar(sx, sy, c, infoclr); + } + } + sx += fontkern[c] + 2; + } +} + +static void PrintInfo() +{ + int yo, lo, i; + + if (!talkflag) { + yo = 0; + lo = 1; + if (infostr[0] != '\0') { + CPrintString(0, infostr, TRUE, pnumlines); + yo = 1; + lo = 0; + } + + for (i = 0; i < pnumlines; i++) { + CPrintString(i + yo, panelstr[i], pstrjust[i], pnumlines - lo); + } + } +} + /** * Sets a string to be drawn in the info box and then draws it. */ @@ -1339,70 +1391,61 @@ void DrawInfoBox() PrintInfo(); } -void PrintInfo() -{ - int yo, lo, i; - if (!talkflag) { - yo = 0; - lo = 1; - if (infostr[0] != '\0') { - CPrintString(0, infostr, TRUE, pnumlines); - yo = 1; - lo = 0; - } - - for (i = 0; i < pnumlines; i++) { - CPrintString(i + yo, panelstr[i], pstrjust[i], pnumlines - lo); - } - } -} +#define ADD_PlrStringXY(x, y, width, pszStr, col) MY_PlrStringXY(x, y, width, pszStr, col, 1) -void CPrintString(int y, const char *str, BOOL center, int lines) +void PrintGameStr(int x, int y, const char *str, int color) { BYTE c; - const char *tmp; - int lineOffset, strWidth, sx, sy; - - lineOffset = 0; - sx = 177 + PANEL_X; - sy = lineOffsets[lines][y] + PANEL_Y; - if (center == TRUE) { - strWidth = 0; - tmp = str; - while (*tmp) { - c = gbFontTransTbl[(BYTE)*tmp++]; - strWidth += fontkern[fontframe[c]] + 2; - } - if (strWidth < 288) - lineOffset = (288 - strWidth) >> 1; - sx += lineOffset; - } + int sx, sy; + sx = x + SCREEN_X; + sy = y + SCREEN_Y; while (*str) { c = gbFontTransTbl[(BYTE)*str++]; c = fontframe[c]; - lineOffset += fontkern[c] + 2; - if (c) { - if (lineOffset < 288) { - PrintChar(sx, sy, c, infoclr); - } - } - sx += fontkern[c] + 2; + if (c) + PrintChar(sx, sy, c, color); + sx += fontkern[c] + 1; } } -void PrintGameStr(int x, int y, const char *str, int color) +/** + * @brief Render text string to back buffer + * @param x Screen coordinate + * @param y Screen coordinate + * @param endX End of line in screen coordinate + * @param pszStr String to print, in Windows-1252 encoding + * @param col text_color color value + * @param base Letter spacing + */ +static void MY_PlrStringXY(int x, int y, int endX, const char *pszStr, char col, int base) { BYTE c; - int sx, sy; + const char *tmp; + int sx, sy, screen_x, line, widthOffset; + sx = x + SCREEN_X; sy = y + SCREEN_Y; - while (*str) { - c = gbFontTransTbl[(BYTE)*str++]; + widthOffset = endX - 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; + sx += line; + while (*pszStr) { + c = gbFontTransTbl[(BYTE)*pszStr++]; c = fontframe[c]; - if (c) - PrintChar(sx, sy, c, color); - sx += fontkern[c] + 1; + line += fontkern[c] + base; + if (c) { + if (line < widthOffset) + PrintChar(sx, sy, c, col); + } + sx += fontkern[c] + base; } } @@ -1628,46 +1671,6 @@ void DrawChr() ADD_PlrStringXY(143, 332, 174, chrstr, col); } -/** - * @brief Render text string to back buffer - * @param x Screen coordinate - * @param y Screen coordinate - * @param endX End of line in screen coordinate - * @param pszStr String to print, in Windows-1252 encoding - * @param col text_color color value - * @param base Letter spacing - */ -void MY_PlrStringXY(int x, int y, int endX, const char *pszStr, char col, int base) -{ - BYTE c; - const char *tmp; - int sx, sy, screen_x, line, widthOffset; - - sx = x + SCREEN_X; - sy = y + SCREEN_Y; - widthOffset = endX - 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; - sx += line; - while (*pszStr) { - c = gbFontTransTbl[(BYTE)*pszStr++]; - c = fontframe[c]; - line += fontkern[c] + base; - if (c) { - if (line < widthOffset) - PrintChar(sx, sy, c, col); - } - sx += fontkern[c] + base; - } -} - void CheckLvlBtn() { if (!lvlbtndown && MouseX >= 40 + PANEL_LEFT && MouseX <= 81 + PANEL_LEFT && MouseY >= -39 + PANEL_TOP && MouseY <= -17 + PANEL_TOP) @@ -1767,33 +1770,7 @@ void ReleaseChrBtns() } } -void DrawDurIcon() -{ - PlayerStruct *p; - int x; - - bool hasRoomBetweenPanels = SCREEN_WIDTH >= PANEL_WIDTH + 16 + (32 + 8 + 32 + 8 + 32 + 8 + 32) + 16; - bool hasRoomUnderPanels = SCREEN_HEIGHT >= SPANEL_HEIGHT + PANEL_HEIGHT + 16 + 32 + 16; - - if (!hasRoomBetweenPanels && !hasRoomUnderPanels) { - if ((chrflag || questlog) && (invflag || sbookflag)) - return; - } - - x = PANEL_X + PANEL_WIDTH - 32 - 16; - if (!hasRoomUnderPanels) { - if (invflag || sbookflag) - x -= SPANEL_WIDTH - (SCREEN_WIDTH - PANEL_WIDTH) / 2; - } - - p = &plr[myplr]; - x = DrawDurIcon4Item(&p->InvBody[INVLOC_HEAD], x, 4); - x = DrawDurIcon4Item(&p->InvBody[INVLOC_CHEST], x, 3); - x = DrawDurIcon4Item(&p->InvBody[INVLOC_HAND_LEFT], x, 0); - DrawDurIcon4Item(&p->InvBody[INVLOC_HAND_RIGHT], x, 0); -} - -int DrawDurIcon4Item(ItemStruct *pItem, int x, int c) +static int DrawDurIcon4Item(ItemStruct *pItem, int x, int c) { if (pItem->_itype == ITYPE_NONE) return x; @@ -1828,6 +1805,32 @@ int DrawDurIcon4Item(ItemStruct *pItem, int x, int c) return x - 32 - 8; } +void DrawDurIcon() +{ + PlayerStruct *p; + int x; + + bool hasRoomBetweenPanels = SCREEN_WIDTH >= PANEL_WIDTH + 16 + (32 + 8 + 32 + 8 + 32 + 8 + 32) + 16; + bool hasRoomUnderPanels = SCREEN_HEIGHT >= SPANEL_HEIGHT + PANEL_HEIGHT + 16 + 32 + 16; + + if (!hasRoomBetweenPanels && !hasRoomUnderPanels) { + if ((chrflag || questlog) && (invflag || sbookflag)) + return; + } + + x = PANEL_X + PANEL_WIDTH - 32 - 16; + if (!hasRoomUnderPanels) { + if (invflag || sbookflag) + x -= SPANEL_WIDTH - (SCREEN_WIDTH - PANEL_WIDTH) / 2; + } + + p = &plr[myplr]; + x = DrawDurIcon4Item(&p->InvBody[INVLOC_HEAD], x, 4); + x = DrawDurIcon4Item(&p->InvBody[INVLOC_CHEST], x, 3); + x = DrawDurIcon4Item(&p->InvBody[INVLOC_HAND_LEFT], x, 0); + DrawDurIcon4Item(&p->InvBody[INVLOC_HAND_RIGHT], x, 0); +} + void RedBack() { int idx; @@ -1861,6 +1864,37 @@ void RedBack() } } +static void PrintSBookStr(int x, int y, BOOL cjustflag, const char *pszStr, char col) +{ + BYTE c; + const char *tmp; + int screen_x, line, sx; + + sx = x + RIGHT_PANEL_X + SPLICONLENGTH; + line = 0; + if (cjustflag) { + screen_x = 0; + tmp = pszStr; + while (*tmp) { + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + 1; + } + if (screen_x < 222) + line = (222 - screen_x) >> 1; + sx += line; + } + while (*pszStr) { + c = gbFontTransTbl[(BYTE)*pszStr++]; + c = fontframe[c]; + line += fontkern[c] + 1; + if (c) { + if (line <= 222) + PrintChar(sx, y, c, col); + } + sx += fontkern[c] + 1; + } +} + char GetSBookTrans(int ii, BOOL townok) { char st; @@ -1955,37 +1989,6 @@ void DrawSpellBook() } } -void PrintSBookStr(int x, int y, BOOL cjustflag, const char *pszStr, char col) -{ - BYTE c; - const char *tmp; - int screen_x, line, sx; - - sx = x + RIGHT_PANEL_X + SPLICONLENGTH; - line = 0; - if (cjustflag) { - screen_x = 0; - tmp = pszStr; - while (*tmp) { - c = gbFontTransTbl[(BYTE)*tmp++]; - screen_x += fontkern[fontframe[c]] + 1; - } - if (screen_x < 222) - line = (222 - screen_x) >> 1; - sx += line; - } - while (*pszStr) { - c = gbFontTransTbl[(BYTE)*pszStr++]; - c = fontframe[c]; - line += fontkern[c] + 1; - if (c) { - if (line <= 222) - PrintChar(sx, y, c, col); - } - sx += fontkern[c] + 1; - } -} - void CheckSBook() { int sn; @@ -2132,6 +2135,30 @@ void control_set_gold_curs(int pnum) NewCursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); } +static char *control_print_talk_msg(char *msg, int *x, int y, int color) +{ + BYTE c; + int width; + + *x += 200 + SCREEN_X; + y += 22 + PANEL_Y; + width = *x; + while (*msg) { + + c = gbFontTransTbl[(BYTE)*msg]; + c = fontframe[c]; + width += fontkern[c] + 1; + if (width > 450 + PANEL_X) + return msg; + msg++; + if (c != 0) { + PrintChar(*x, y, c, color); + } + *x += fontkern[c] + 1; + } + return NULL; +} + void DrawTalkPan() { int i, off, talk_btn, color, nCel, x; @@ -2193,30 +2220,6 @@ void DrawTalkPan() } } -char *control_print_talk_msg(char *msg, int *x, int y, int color) -{ - BYTE c; - int width; - - *x += 200 + SCREEN_X; - y += 22 + PANEL_Y; - width = *x; - while (*msg) { - - c = gbFontTransTbl[(BYTE)*msg]; - c = fontframe[c]; - width += fontkern[c] + 1; - if (width > 450 + PANEL_X) - return msg; - msg++; - if (c != 0) { - PrintChar(*x, y, c, color); - } - *x += fontkern[c] + 1; - } - return NULL; -} - BOOL control_check_talk_btn() { int i; @@ -2301,6 +2304,46 @@ void control_reset_talk() force_redraw = 255; } +static void control_press_enter() +{ + int i; + BYTE talk_save; + + if (sgszTalkMsg[0] != 0) { +#ifdef HELLFIRE + int pmask; + pmask = 0; + + for (i = 0; i < MAX_PLRS; i++) { + if (whisper[i]) + pmask |= 1 << i; + } + NetSendCmdString(pmask, sgszTalkMsg); +#else + control_reset_talk_msg(sgszTalkMsg); +#endif + for (i = 0; i < 8; i++) { + if (!strcmp(sgszTalkSave[i], sgszTalkMsg)) + break; + } + if (i >= 8) { + strcpy(sgszTalkSave[sgbNextTalkSave], sgszTalkMsg); + sgbNextTalkSave++; + sgbNextTalkSave &= 7; + } else { + talk_save = sgbNextTalkSave - 1; + talk_save &= 7; + if (i != talk_save) { + strcpy(sgszTalkSave[i], sgszTalkSave[talk_save]); + strcpy(sgszTalkSave[talk_save], sgszTalkMsg); + } + } + sgszTalkMsg[0] = '\0'; + sgbTalkSavePos = sgbNextTalkSave; + } + control_reset_talk(); +} + BOOL control_talk_last_key(int vkey) { int result; @@ -2322,6 +2365,19 @@ BOOL control_talk_last_key(int vkey) return TRUE; } +static void control_up_down(int v) +{ + int i; + + for (i = 0; i < 8; i++) { + sgbTalkSavePos = (v + sgbTalkSavePos) & 7; + if (sgszTalkSave[sgbTalkSavePos][0]) { + strcpy(sgszTalkMsg, sgszTalkSave[sgbTalkSavePos]); + return; + } + } +} + BOOL control_presskeys(int vkey) { int len; @@ -2355,57 +2411,4 @@ BOOL control_presskeys(int vkey) return ret; } -void control_press_enter() -{ - int i; - BYTE talk_save; - - if (sgszTalkMsg[0] != 0) { -#ifdef HELLFIRE - int pmask; - pmask = 0; - - for (i = 0; i < MAX_PLRS; i++) { - if (whisper[i]) - pmask |= 1 << i; - } - NetSendCmdString(pmask, sgszTalkMsg); -#else - control_reset_talk_msg(sgszTalkMsg); -#endif - for (i = 0; i < 8; i++) { - if (!strcmp(sgszTalkSave[i], sgszTalkMsg)) - break; - } - if (i >= 8) { - strcpy(sgszTalkSave[sgbNextTalkSave], sgszTalkMsg); - sgbNextTalkSave++; - sgbNextTalkSave &= 7; - } else { - talk_save = sgbNextTalkSave - 1; - talk_save &= 7; - if (i != talk_save) { - strcpy(sgszTalkSave[i], sgszTalkSave[talk_save]); - strcpy(sgszTalkSave[talk_save], sgszTalkMsg); - } - } - sgszTalkMsg[0] = '\0'; - sgbTalkSavePos = sgbNextTalkSave; - } - control_reset_talk(); -} - -void control_up_down(int v) -{ - int i; - - for (i = 0; i < 8; i++) { - sgbTalkSavePos = (v + sgbTalkSavePos) & 7; - if (sgszTalkSave[sgbTalkSavePos][0]) { - strcpy(sgszTalkMsg, sgszTalkSave[sgbTalkSavePos]); - return; - } - } -} - DEVILUTION_END_NAMESPACE diff --git a/Source/control.h b/Source/control.h index 42628898d..05e88853b 100644 --- a/Source/control.h +++ b/Source/control.h @@ -12,58 +12,34 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -extern BYTE *pDurIcons; -extern BYTE *pChrButtons; extern BOOL drawhpflag; extern BOOL dropGoldFlag; extern BOOL panbtn[8]; extern BOOL chrbtn[4]; -extern BYTE *pMultiBtns; -extern BYTE *pPanelButtons; -extern BYTE *pChrPanel; extern BOOL lvlbtndown; extern int dropGoldValue; extern BOOL drawmanaflag; extern BOOL chrbtnactive; extern BYTE *pPanelText; -extern BYTE *pLifeBuff; -extern BYTE *pBtmBuff; -extern BYTE *pTalkBtns; -extern int pstrjust[4]; -extern int pnumlines; extern BOOL pinfoflag; -extern BOOL talkbtndown[3]; extern int pSpell; -extern BYTE *pManaBuff; extern char infoclr; -extern BYTE *pGBoxBuff; -extern BYTE *pSBkBtnCel; extern char tempstr[256]; extern BOOLEAN whisper[MAX_PLRS]; extern int sbooktab; extern int pSplType; extern int initialDropGoldIndex; extern BOOL talkflag; -extern BYTE *pSBkIconCels; extern BOOL sbookflag; extern BOOL chrflag; extern BOOL drawbtnflag; -extern BYTE *pSpellBkCel; extern char infostr[256]; -extern int numpanbtns; -extern BYTE *pStatusPanel; extern char panelstr[4][64]; extern BOOL panelflag; -extern BYTE SplTransTbl[256]; extern int initialDropGoldValue; -extern BYTE *pSpellCels; extern BOOL panbtndown; -extern BYTE *pTalkPanel; extern BOOL spselflag; -void DrawSpellCel(int xp, int yp, BYTE *Trans, int nCel, int w); -void SetSpellTrans(char t); -void DrawSpell(); void DrawSpellList(); void SetSpell(); void SetSpeedSpell(int slot); @@ -72,9 +48,6 @@ void PrintChar(int sx, int sy, int nCel, char col); void AddPanelString(const char *str, BOOL just); void ClearPanel(); void DrawPanelBox(int x, int y, int w, int h, int sx, int sy); -void InitPanelStr(); -void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy); -void DrawFlask(BYTE *pCelBuff, int w, int nSrcOff, BYTE *pBuff, int nDstOff, int h); void DrawLifeFlask(); void UpdateLifeFlask(); void DrawManaFlask(); @@ -85,7 +58,6 @@ void DrawCtrlPan(); void DrawCtrlBtns(); void DoSpeedBook(); void DoPanBtn(); -void control_set_button_down(int btn_id); void control_check_btn_press(); void DoAutoMap(); void CheckPanelInfo(); @@ -93,23 +65,16 @@ void CheckBtnUp(); void FreeControlPan(); BOOL control_WriteStringToBuffer(BYTE *str); void DrawInfoBox(); -void PrintInfo(); -void CPrintString(int y, const char *str, BOOL center, int lines); void PrintGameStr(int x, int y, const char *str, int color); void DrawChr(); -#define ADD_PlrStringXY(x, y, width, pszStr, col) MY_PlrStringXY(x, y, width, pszStr, col, 1) -void MY_PlrStringXY(int x, int y, int width, const char *pszStr, char col, int base); void CheckLvlBtn(); void ReleaseLvlBtn(); void DrawLevelUpIcon(); void CheckChrBtns(); void ReleaseChrBtns(); void DrawDurIcon(); -int DrawDurIcon4Item(ItemStruct *pItem, int x, int c); void RedBack(); -char GetSBookTrans(int ii, BOOL townok); void DrawSpellBook(); -void PrintSBookStr(int x, int y, BOOL cjustflag, const char *pszStr, char col); void CheckSBook(); const char *get_pieces_str(int nGold); void DrawGoldSplit(int amount); @@ -117,31 +82,22 @@ void control_drop_gold(char vkey); void control_remove_gold(int pnum, int gold_index); void control_set_gold_curs(int pnum); void DrawTalkPan(); -char *control_print_talk_msg(char *msg, int *x, int y, int just); BOOL control_check_talk_btn(); void control_release_talk_btn(); -void control_reset_talk_msg(); void control_type_message(); void control_reset_talk(); BOOL control_talk_last_key(int vkey); BOOL control_presskeys(int vkey); -void control_press_enter(); -void control_up_down(int v); /* rdata */ extern const BYTE fontframe[128]; extern const BYTE fontkern[68]; -extern const int lineOffsets[5][5]; extern const BYTE gbFontTransTbl[256]; /* data */ -extern char SpellITbl[MAX_SPELLS]; -extern int PanBtnPos[8][5]; -extern const char *const PanBtnHotKey[8]; -extern const char *const PanBtnStr[8]; extern RECT32 ChrBtnsRect[4]; -extern int SpellPages[6][7]; + #ifdef __cplusplus } diff --git a/Source/cursor.h b/Source/cursor.h index aa9971f83..bc3bc481d 100644 --- a/Source/cursor.h +++ b/Source/cursor.h @@ -29,7 +29,6 @@ extern char pcursobj; extern char pcursplr; extern int cursmx; extern int cursmy; -extern int pcurstemp; extern int pcurs; void InitCursor(); @@ -38,8 +37,8 @@ void SetICursor(int i); void SetCursor_(int i); void NewCursor(int i); void InitLevelCursor(); -void CheckTown(); void CheckRportal(); +void CheckTown(); void CheckCursMove(); /* rdata */ diff --git a/Source/dead.h b/Source/dead.h index 16c3c5243..e5139f59f 100644 --- a/Source/dead.h +++ b/Source/dead.h @@ -12,7 +12,6 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -extern int spurtndx; extern DeadStruct dead[MAXDEAD]; extern int stonendx; diff --git a/Source/debug.h b/Source/debug.h index 1a210a41e..2f38a3680 100644 --- a/Source/debug.h +++ b/Source/debug.h @@ -13,8 +13,6 @@ extern "C" { #endif extern BYTE *pSquareCel; -extern char dMonsDbg[NUMLEVELS][MAXDUNX][MAXDUNY]; -extern char dFlagDbg[NUMLEVELS][MAXDUNX][MAXDUNY]; void LoadDebugGFX(); void FreeDebugGFX(); @@ -24,11 +22,9 @@ void GiveGoldCheat(); void StoresCheat(); void TakeGoldCheat(); void MaxSpellsCheat(); -void SetSpellLevelCheat(char spl, int spllvl); void SetAllSpellsCheat(); void PrintDebugPlayer(BOOL bNextPlayer); void PrintDebugQuest(); -void PrintDebugMonster(int m); void GetDebugMonster(); void NextDebugMonster(); #endif diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 3459f00fd..22c836320 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1597,7 +1597,7 @@ void LoadGameLevel(BOOL firstflag, int lvldir) IncProgress(); InitAutomap(); - if (leveltype != DTYPE_TOWN && lvldir != 4) { + if (leveltype != DTYPE_TOWN && lvldir != ENTRY_LOAD) { InitLighting(); InitVision(); } @@ -1625,9 +1625,9 @@ void LoadGameLevel(BOOL firstflag, int lvldir) IncProgress(); - if (lvldir == 3) + if (lvldir == ENTRY_RTNLVL) GetReturnLvlPos(); - if (lvldir == 5) + if (lvldir == ENTRY_WARPLVL) GetPortalLvlPos(); IncProgress(); @@ -1635,7 +1635,7 @@ void LoadGameLevel(BOOL firstflag, int lvldir) for (i = 0; i < MAX_PLRS; i++) { if (plr[i].plractive && currlevel == plr[i].plrlevel) { InitPlayerGFX(i); - if (lvldir != 4) + if (lvldir != ENTRY_LOAD) InitPlayer(i, firstflag); } } @@ -1653,7 +1653,7 @@ void LoadGameLevel(BOOL firstflag, int lvldir) SetRndSeed(glSeedTbl[currlevel]); if (leveltype != DTYPE_TOWN) { - if (firstflag || lvldir == 4 || !plr[myplr]._pLvlVisited[currlevel] || gbMaxPlayers != 1) { + if (firstflag || lvldir == ENTRY_LOAD || !plr[myplr]._pLvlVisited[currlevel] || gbMaxPlayers != 1) { HoldThemeRooms(); glMid1Seed[currlevel] = GetRndSeed(); InitMonsters(); @@ -1695,7 +1695,7 @@ void LoadGameLevel(BOOL firstflag, int lvldir) InitMissiles(); IncProgress(); - if (!firstflag && lvldir != 4 && plr[myplr]._pLvlVisited[currlevel] && gbMaxPlayers == 1) + if (!firstflag && lvldir != ENTRY_LOAD && plr[myplr]._pLvlVisited[currlevel] && gbMaxPlayers == 1) LoadLevel(); if (gbMaxPlayers != 1) DeltaLoadLevel(); @@ -1720,14 +1720,14 @@ void LoadGameLevel(BOOL firstflag, int lvldir) FillSolidBlockTbls(); IncProgress(); - if (lvldir == 5) + if (lvldir == ENTRY_WARPLVL) GetPortalLvlPos(); IncProgress(); for (i = 0; i < MAX_PLRS; i++) { if (plr[i].plractive && currlevel == plr[i].plrlevel) { InitPlayerGFX(i); - if (lvldir != 4) + if (lvldir != ENTRY_LOAD) InitPlayer(i, firstflag); } } @@ -1736,7 +1736,7 @@ void LoadGameLevel(BOOL firstflag, int lvldir) InitMultiView(); IncProgress(); - if (firstflag || lvldir == 4 || !plr[myplr]._pSLvlVisited[setlvlnum]) { + if (firstflag || lvldir == ENTRY_LOAD || !plr[myplr]._pSLvlVisited[setlvlnum]) { InitItems(); SavePreLighting(); } else { diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 49448a491..a272fb488 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -2593,7 +2593,7 @@ static void DRLG_L5(int entry) doneflag = TRUE; if (QuestStatus(Q_PWATER)) { - if (entry == 0) { + if (entry == ENTRY_MAIN) { if (DRLG_PlaceMiniSet(PWATERIN, 1, 1, 0, 0, TRUE, -1, 0) < 0) doneflag = FALSE; } else { @@ -2603,13 +2603,13 @@ static void DRLG_L5(int entry) } } if (QuestStatus(Q_LTBANNER)) { - if (entry == 0) { + if (entry == ENTRY_MAIN) { if (DRLG_PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, TRUE, -1, 0) < 0) doneflag = FALSE; } else { if (DRLG_PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, FALSE, -1, 0) < 0) doneflag = FALSE; - if (entry == 1) { + if (entry == ENTRY_PREV) { ViewX = 2 * setpc_x + 20; ViewY = 2 * setpc_y + 28; } else { @@ -2698,7 +2698,7 @@ static void DRLG_L5(int entry) } } #else - } else if (entry == 0) { + } else if (entry == ENTRY_MAIN) { if (DRLG_PlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, TRUE, -1, 0) < 0) doneflag = FALSE; else if (DRLG_PlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, FALSE, -1, 1) < 0) diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index b55fa6b6d..9f046f0d5 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -3129,7 +3129,7 @@ static void DRLG_L2(int entry) } DRLG_L2FloodTVal(); DRLG_L2TransFix(); - if (entry == 0) { + if (entry == ENTRY_MAIN) { doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, TRUE, 0); if (doneflag) { doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, FALSE, 1); @@ -3138,7 +3138,7 @@ static void DRLG_L2(int entry) } } ViewY -= 2; - } else if (entry == 1) { + } else if (entry == ENTRY_PREV) { doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, FALSE, 0); if (doneflag) { doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, TRUE, 1); diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 500822a79..8db709ec1 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -2358,7 +2358,7 @@ static void DRLG_L3(int entry) } } while (!found); DRLG_L3MakeMegas(); - if (entry == 0) { + if (entry == ENTRY_MAIN) { #ifdef HELLFIRE if (currlevel < 17) { #endif @@ -2386,7 +2386,7 @@ static void DRLG_L3(int entry) genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, FALSE, 6); } } - } else if (entry == 1) { + } else if (entry == ENTRY_PREV) { #ifdef HELLFIRE if (currlevel < 17) { #endif diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index e23b79d96..184e17e54 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -1618,13 +1618,13 @@ static void DRLG_L4(int entry) DRLG_LoadDiabQuads(TRUE); } if (QuestStatus(Q_WARLORD)) { - if (entry == 0) { + if (entry == ENTRY_MAIN) { doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, TRUE, 0); if (doneflag && currlevel == 13) { doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, FALSE, 6); } ViewX++; - } else if (entry == 1) { + } else if (entry == ENTRY_PREV) { doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, FALSE, 0); if (doneflag && currlevel == 13) { doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, FALSE, 6); @@ -1639,7 +1639,7 @@ static void DRLG_L4(int entry) ViewX++; } } else if (currlevel != 15) { - if (entry == 0) { + if (entry == ENTRY_MAIN) { doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, TRUE, 0); if (doneflag && currlevel != 16) { doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, FALSE, 1); @@ -1648,7 +1648,7 @@ static void DRLG_L4(int entry) doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, FALSE, 6); } ViewX++; - } else if (entry == 1) { + } else if (entry == ENTRY_PREV) { doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, FALSE, 0); if (doneflag && currlevel != 16) { doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, TRUE, 1); @@ -1668,7 +1668,7 @@ static void DRLG_L4(int entry) ViewX++; } } else { - if (entry == 0) { + if (entry == ENTRY_MAIN) { doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, TRUE, 0); if (doneflag) { if (gbMaxPlayers == 1 && quests[Q_DIABLO]._qactive != QUEST_ACTIVE) { diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 90b9e66df..5b8195b21 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -105,7 +105,7 @@ void ShowProgress(unsigned int uMsg) IncProgress(); pfile_remove_temp_files(); IncProgress(); - LoadGameLevel(TRUE, 0); + LoadGameLevel(TRUE, ENTRY_MAIN); IncProgress(); break; case WM_DIABNEXTLVL: @@ -121,7 +121,7 @@ void ShowProgress(unsigned int uMsg) leveltype = gnLevelTypeTbl[currlevel]; assert(plr[myplr].plrlevel == currlevel); IncProgress(); - LoadGameLevel(FALSE, 0); + LoadGameLevel(FALSE, ENTRY_MAIN); IncProgress(); break; case WM_DIABPREVLVL: @@ -137,7 +137,7 @@ void ShowProgress(unsigned int uMsg) leveltype = gnLevelTypeTbl[currlevel]; assert(plr[myplr].plrlevel == currlevel); IncProgress(); - LoadGameLevel(FALSE, 1); + LoadGameLevel(FALSE, ENTRY_PREV); IncProgress(); break; case WM_DIABSETLVL: @@ -153,7 +153,7 @@ void ShowProgress(unsigned int uMsg) leveltype = setlvltype; FreeGameMem(); IncProgress(); - LoadGameLevel(FALSE, 2); + LoadGameLevel(FALSE, ENTRY_SETLVL); IncProgress(); break; case WM_DIABRTNLVL: @@ -168,7 +168,7 @@ void ShowProgress(unsigned int uMsg) FreeGameMem(); IncProgress(); GetReturnLvlPos(); - LoadGameLevel(FALSE, 3); + LoadGameLevel(FALSE, ENTRY_RTNLVL); IncProgress(); break; case WM_DIABWARPLVL: @@ -182,7 +182,7 @@ void ShowProgress(unsigned int uMsg) FreeGameMem(); GetPortalLevel(); IncProgress(); - LoadGameLevel(FALSE, 5); + LoadGameLevel(FALSE, ENTRY_WARPLVL); IncProgress(); break; case WM_DIABTOWNWARP: @@ -198,7 +198,7 @@ void ShowProgress(unsigned int uMsg) leveltype = gnLevelTypeTbl[currlevel]; assert(plr[myplr].plrlevel == currlevel); IncProgress(); - LoadGameLevel(FALSE, 6); + LoadGameLevel(FALSE, ENTRY_TWARPDN); IncProgress(); break; case WM_DIABTWARPUP: @@ -214,7 +214,7 @@ void ShowProgress(unsigned int uMsg) leveltype = gnLevelTypeTbl[currlevel]; assert(plr[myplr].plrlevel == currlevel); IncProgress(); - LoadGameLevel(FALSE, 7); + LoadGameLevel(FALSE, ENTRY_TWARPUP); IncProgress(); break; case WM_DIABRETOWN: @@ -230,7 +230,7 @@ void ShowProgress(unsigned int uMsg) leveltype = gnLevelTypeTbl[currlevel]; assert(plr[myplr].plrlevel == currlevel); IncProgress(); - LoadGameLevel(FALSE, 0); + LoadGameLevel(FALSE, ENTRY_MAIN); IncProgress(); break; } diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index c8b3b6097..6d5448ee2 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -63,7 +63,7 @@ void LoadGame(BOOL firstflag) for (i = 0; i < MAXPORTAL; i++) LoadPortal(i); - LoadGameLevel(firstflag, 4); + LoadGameLevel(firstflag, ENTRY_LOAD); SyncInitPlr(myplr); SyncPlrAnim(myplr); diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 3256f3e47..fcc13877f 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -220,6 +220,11 @@ void nthread_ignore_mutex(BOOL bStart) } } +/** + * @brief Checks if it's time for the logic to advance + * @param unused + * @return True if the engine should tick + */ BOOL nthread_has_500ms_passed(BOOL unused) { DWORD currentTickCount; diff --git a/Source/sha.cpp b/Source/sha.cpp index f0dcdb07c..1e595e00c 100644 --- a/Source/sha.cpp +++ b/Source/sha.cpp @@ -32,51 +32,18 @@ uint32_t SHA1CircularShift(uint32_t bits, uint32_t word) { SHA1Context sgSHA1[3]; -void SHA1Clear() +static void SHA1Init(SHA1Context *context) { - memset(sgSHA1, 0, sizeof(sgSHA1)); -} - -void SHA1Result(int n, char Message_Digest[SHA1HashSize]) -{ - DWORD *Message_Digest_Block; - int i; - - Message_Digest_Block = (DWORD *)Message_Digest; - if (Message_Digest) { - for (i = 0; i < 5; i++) { - *Message_Digest_Block = SwapLE32(sgSHA1[n].state[i]); - Message_Digest_Block++; - } - } -} - -void SHA1Calculate(int n, const char *data, char Message_Digest[SHA1HashSize]) -{ - SHA1Input(&sgSHA1[n], data, 64); - if (Message_Digest) - SHA1Result(n, Message_Digest); -} - -void SHA1Input(SHA1Context *context, const char *message_array, int len) -{ - int i, count; - - count = context->count[0] + 8 * len; - if (count < context->count[0]) - context->count[1]++; - - context->count[0] = count; - context->count[1] += len >> 29; - - for (i = len; i >= 64; i -= 64) { - memcpy(context->buffer, message_array, sizeof(context->buffer)); - SHA1ProcessMessageBlock(context); - message_array += 64; - } + context->count[0] = 0; + context->count[1] = 0; + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; + context->state[4] = 0xC3D2E1F0; } -void SHA1ProcessMessageBlock(SHA1Context *context) +static void SHA1ProcessMessageBlock(SHA1Context *context) { DWORD i, temp; DWORD W[80]; @@ -140,20 +107,53 @@ void SHA1ProcessMessageBlock(SHA1Context *context) context->state[4] += E; } -void SHA1Reset(int n) +static void SHA1Input(SHA1Context *context, const char *message_array, int len) { - SHA1Init(&sgSHA1[n]); + int i, count; + + count = context->count[0] + 8 * len; + if (count < context->count[0]) + context->count[1]++; + + context->count[0] = count; + context->count[1] += len >> 29; + + for (i = len; i >= 64; i -= 64) { + memcpy(context->buffer, message_array, sizeof(context->buffer)); + SHA1ProcessMessageBlock(context); + message_array += 64; + } } -void SHA1Init(SHA1Context *context) +void SHA1Clear() { - context->count[0] = 0; - context->count[1] = 0; - context->state[0] = 0x67452301; - context->state[1] = 0xEFCDAB89; - context->state[2] = 0x98BADCFE; - context->state[3] = 0x10325476; - context->state[4] = 0xC3D2E1F0; + memset(sgSHA1, 0, sizeof(sgSHA1)); +} + +void SHA1Result(int n, char Message_Digest[SHA1HashSize]) +{ + DWORD *Message_Digest_Block; + int i; + + Message_Digest_Block = (DWORD *)Message_Digest; + if (Message_Digest) { + for (i = 0; i < 5; i++) { + *Message_Digest_Block = SwapLE32(sgSHA1[n].state[i]); + Message_Digest_Block++; + } + } +} + +void SHA1Calculate(int n, const char *data, char Message_Digest[SHA1HashSize]) +{ + SHA1Input(&sgSHA1[n], data, 64); + if (Message_Digest) + SHA1Result(n, Message_Digest); +} + +void SHA1Reset(int n) +{ + SHA1Init(&sgSHA1[n]); } DEVILUTION_END_NAMESPACE diff --git a/Source/sha.h b/Source/sha.h index be3cc9e1a..9d00a3994 100644 --- a/Source/sha.h +++ b/Source/sha.h @@ -14,15 +14,10 @@ extern "C" { #define SHA1HashSize 20 -//sha - void SHA1Clear(); void SHA1Result(int n, char Message_Digest[SHA1HashSize]); void SHA1Calculate(int n, const char *data, char Message_Digest[SHA1HashSize]); -void SHA1Input(SHA1Context *context, const char *message_array, int len); -void SHA1ProcessMessageBlock(SHA1Context *context); void SHA1Reset(int n); -void SHA1Init(SHA1Context *context); #ifdef __cplusplus } diff --git a/Source/town.cpp b/Source/town.cpp index 921b02b72..0a26eac02 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -324,13 +324,13 @@ void CreateTown(int entry) DRLG_InitTrans(); DRLG_Init_Globals(); - if (entry == 0) { + if (entry == ENTRY_MAIN) { // New game ViewX = 75; ViewY = 68; - } else if (entry == 1) { + } else if (entry == ENTRY_PREV) { // Cathedral ViewX = 25; ViewY = 31; - } else if (entry == 7) { + } else if (entry == ENTRY_TWARPUP) { if (TWarpFrom == 5) { ViewX = 49; ViewY = 22; diff --git a/enums.h b/enums.h index 0efd5333a..197cf4402 100644 --- a/enums.h +++ b/enums.h @@ -2508,6 +2508,17 @@ typedef enum interface_mode { // WM_DIAVNEWLVL = 0x40D, // psx only } interface_mode; +typedef enum lvl_entry { + ENTRY_MAIN = 0, + ENTRY_PREV = 1, + ENTRY_SETLVL = 2, + ENTRY_RTNLVL = 3, + ENTRY_LOAD = 4, + ENTRY_WARPLVL = 5, + ENTRY_TWARPDN = 6, + ENTRY_TWARPUP = 7, +} lvl_entry; + typedef enum game_info { GAMEINFO_NAME = 1, GAMEINFO_PASSWORD = 2,