diff --git a/.travis.yml b/.travis.yml index 0f1d1e4f5..adfa3bcd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,8 +57,8 @@ jobs: script: - | set -e - wget https://github.com/diasurgical/devilution-comparer/releases/download/v0.3.3/devilution-comparer-v0.3.3-x86_64-unknown-linux-gnu.tar.xz - tar xf devilution-comparer-v0.3.3-x86_64-unknown-linux-gnu.tar.xz + wget https://github.com/diasurgical/devilution-comparer/releases/download/v0.3.4/devilution-comparer-v0.3.4-x86_64-unknown-linux-gnu.tar.xz + tar xf devilution-comparer-v0.3.4-x86_64-unknown-linux-gnu.tar.xz echo '#!/bin/sh' | sudo tee /bin/wine echo 'docker run -v $(pwd):/root/devilution --entrypoint "/usr/bin/wine" diasurgical/riivaaja:stable $(basename $1) $2 $3' | sudo tee --append /bin/wine sudo chmod +x /bin/wine diff --git a/DiabloUI/diabloui.cpp b/DiabloUI/diabloui.cpp index f4a9f4463..0058a00de 100644 --- a/DiabloUI/diabloui.cpp +++ b/DiabloUI/diabloui.cpp @@ -17,8 +17,8 @@ #include "..\structs.h" #include "diabloui.h" -BOOL APIENTRY DllMain( HANDLE hModule, - DWORD ul_reason_for_call, +BOOL APIENTRY DllMain( HANDLE hModule, + DWORD ul_reason_for_call, LPVOID lpReserved ) { diff --git a/Source/appfat.cpp b/Source/appfat.cpp index e9b991be3..bc1560127 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -1,434 +1,434 @@ -//HEADER_GOES_HERE - -#include "../types.h" - -// +Infinity after initialization of appfat.cpp. -float appfat_cpp_init_value; - -char sz_error_buf[256]; -int terminating; // weak -int cleanup_thread_id; // weak -char empty_string; - -// appfat_cpp_init initializes the C++ runtime of appfat.cpp. -struct appfat_cpp_init { - appfat_cpp_init() { - appfat_cpp_init_value = INFINITY; - } -} appfat_cpp_init; - -// delete overloads the delete operator. -void operator delete(void *ptr) { - if (ptr != NULL) { - SMemFree(ptr, "delete", -1, 0); - } -} - -char *__fastcall GetErr(int error_code) -{ - int v1; // edi - unsigned int v2; // eax - signed int v4; // eax - char *i; // ecx - - v1 = error_code; - v2 = ((unsigned int)error_code >> 16) & 0x1FFF; - if ( v2 == 0x0878 ) - { - GetDSErr(error_code, sz_error_buf, 256); - } - else if ( v2 == 0x0876 ) - { - GetDDErr(error_code, sz_error_buf, 256); - } - else - { - if ( !SErrGetErrorStr(error_code, sz_error_buf, 256) && !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, v1, 0x400u, sz_error_buf, 0x100u, NULL) ) - wsprintf(sz_error_buf, "unknown error 0x%08x", v1); - } - v4 = strlen(sz_error_buf); - for ( i = &sz_error_buf[v4-1]; v4 > 0; *i = 0 ) - { - --v4; - --i; - if ( *i != '\r' && *i != '\n' ) - break; - } - return sz_error_buf; -} - -#define CASE_ERROR(v, errName) case errName: v = #errName; break; - -void __fastcall GetDDErr(int error_code, char *error_buf, int error_buf_len) -{ - const char *v3; // eax - char v4[20]; // [esp+0h] [ebp-14h] - - switch (error_code) { - CASE_ERROR(v3, DDERR_CANTPAGEUNLOCK); - CASE_ERROR(v3, DDERR_NOTPAGELOCKED); - CASE_ERROR(v3, DD_OK); - CASE_ERROR(v3, DDERR_CANTPAGELOCK); - CASE_ERROR(v3, DDERR_BLTFASTCANTCLIP); - CASE_ERROR(v3, DDERR_NOBLTHW); - CASE_ERROR(v3, DDERR_NODDROPSHW); - CASE_ERROR(v3, DDERR_OVERLAYNOTVISIBLE); - CASE_ERROR(v3, DDERR_NOOVERLAYDEST); - CASE_ERROR(v3, DDERR_INVALIDPOSITION); - CASE_ERROR(v3, DDERR_NOTAOVERLAYSURFACE); - CASE_ERROR(v3, DDERR_EXCLUSIVEMODEALREADYSET); - CASE_ERROR(v3, DDERR_NOTFLIPPABLE); - CASE_ERROR(v3, DDERR_CANTDUPLICATE); - CASE_ERROR(v3, DDERR_NOTLOCKED); - CASE_ERROR(v3, DDERR_CANTCREATEDC); - CASE_ERROR(v3, DDERR_NODC); - CASE_ERROR(v3, DDERR_WRONGMODE); - CASE_ERROR(v3, DDERR_IMPLICITLYCREATED); - CASE_ERROR(v3, DDERR_NOTPALETTIZED); - CASE_ERROR(v3, DDERR_NOMIPMAPHW); - CASE_ERROR(v3, DDERR_INVALIDSURFACETYPE); - CASE_ERROR(v3, DDERR_DCALREADYCREATED); - CASE_ERROR(v3, DDERR_NOPALETTEHW); - CASE_ERROR(v3, DDERR_DIRECTDRAWALREADYCREATED); - CASE_ERROR(v3, DDERR_NODIRECTDRAWHW); - CASE_ERROR(v3, DDERR_PRIMARYSURFACEALREADYEXISTS); - CASE_ERROR(v3, DDERR_NOEMULATION); - CASE_ERROR(v3, DDERR_REGIONTOOSMALL); - CASE_ERROR(v3, DDERR_CLIPPERISUSINGHWND); - CASE_ERROR(v3, DDERR_NOCLIPPERATTACHED); - CASE_ERROR(v3, DDERR_NOHWND); - CASE_ERROR(v3, DDERR_HWNDSUBCLASSED); - CASE_ERROR(v3, DDERR_HWNDALREADYSET); - CASE_ERROR(v3, DDERR_NOPALETTEATTACHED); - CASE_ERROR(v3, DDERR_INVALIDDIRECTDRAWGUID); - CASE_ERROR(v3, DDERR_UNSUPPORTEDFORMAT); - CASE_ERROR(v3, DDERR_UNSUPPORTEDMASK); - CASE_ERROR(v3, DDERR_VERTICALBLANKINPROGRESS); - CASE_ERROR(v3, DDERR_WASSTILLDRAWING); - CASE_ERROR(v3, DDERR_XALIGN); - CASE_ERROR(v3, DDERR_TOOBIGWIDTH); - CASE_ERROR(v3, DDERR_CANTLOCKSURFACE); - CASE_ERROR(v3, DDERR_SURFACEISOBSCURED); - CASE_ERROR(v3, DDERR_SURFACELOST); - CASE_ERROR(v3, DDERR_SURFACENOTATTACHED); - CASE_ERROR(v3, DDERR_TOOBIGHEIGHT); - CASE_ERROR(v3, DDERR_TOOBIGSIZE); - CASE_ERROR(v3, DDERR_SURFACEBUSY); - CASE_ERROR(v3, DDERR_OVERLAYCOLORKEYONLYONEACTIVE); - CASE_ERROR(v3, DDERR_PALETTEBUSY); - CASE_ERROR(v3, DDERR_COLORKEYNOTSET); - CASE_ERROR(v3, DDERR_SURFACEALREADYATTACHED); - CASE_ERROR(v3, DDERR_SURFACEALREADYDEPENDENT); - CASE_ERROR(v3, DDERR_OVERLAYCANTCLIP); - CASE_ERROR(v3, DDERR_NOVSYNCHW); - CASE_ERROR(v3, DDERR_NOZBUFFERHW); - CASE_ERROR(v3, DDERR_NOZOVERLAYHW); - CASE_ERROR(v3, DDERR_OUTOFCAPS); - CASE_ERROR(v3, DDERR_OUTOFVIDEOMEMORY); - CASE_ERROR(v3, DDERR_NOTEXTUREHW); - CASE_ERROR(v3, DDERR_NOROTATIONHW); - CASE_ERROR(v3, DDERR_NOSTRETCHHW); - CASE_ERROR(v3, DDERR_NOT4BITCOLOR); - CASE_ERROR(v3, DDERR_NOT4BITCOLORINDEX); - CASE_ERROR(v3, DDERR_NOT8BITCOLOR); - CASE_ERROR(v3, DDERR_NORASTEROPHW); - CASE_ERROR(v3, DDERR_NOEXCLUSIVEMODE); - CASE_ERROR(v3, DDERR_NOFLIPHW); - CASE_ERROR(v3, DDERR_NOGDI); - CASE_ERROR(v3, DDERR_NOMIRRORHW); - CASE_ERROR(v3, DDERR_NOTFOUND); - CASE_ERROR(v3, DDERR_NOOVERLAYHW); - CASE_ERROR(v3, DDERR_NOCOLORKEYHW); - CASE_ERROR(v3, DDERR_NOALPHAHW); - CASE_ERROR(v3, DDERR_NOCLIPLIST); - CASE_ERROR(v3, DDERR_NOCOLORCONVHW); - CASE_ERROR(v3, DDERR_NOCOOPERATIVELEVELSET); - CASE_ERROR(v3, DDERR_NOCOLORKEY); - CASE_ERROR(v3, DDERR_NO3D); - CASE_ERROR(v3, DDERR_INVALIDMODE); - CASE_ERROR(v3, DDERR_INVALIDOBJECT); - CASE_ERROR(v3, DDERR_INVALIDPIXELFORMAT); - CASE_ERROR(v3, DDERR_INVALIDRECT); - CASE_ERROR(v3, DDERR_LOCKEDSURFACES); - CASE_ERROR(v3, DDERR_INVALIDCLIPLIST); - CASE_ERROR(v3, DDERR_CURRENTLYNOTAVAIL); - CASE_ERROR(v3, DDERR_EXCEPTION); - CASE_ERROR(v3, DDERR_HEIGHTALIGN); - CASE_ERROR(v3, DDERR_INCOMPATIBLEPRIMARY); - CASE_ERROR(v3, DDERR_INVALIDCAPS); - CASE_ERROR(v3, DDERR_CANNOTDETACHSURFACE); - CASE_ERROR(v3, DDERR_UNSUPPORTED); - CASE_ERROR(v3, DDERR_GENERIC); - CASE_ERROR(v3, DDERR_OUTOFMEMORY); - CASE_ERROR(v3, DDERR_INVALIDPARAMS); - CASE_ERROR(v3, DDERR_ALREADYINITIALIZED); - CASE_ERROR(v3, DDERR_CANNOTATTACHSURFACE); - default: - strcpy(v4, "DDERR unknown 0x%x"); - sprintf(error_buf, v4, error_code); - return; - } - strncpy(error_buf, v3, error_buf_len); -} - -void __fastcall GetDSErr(int error_code, char *error_buf, int error_buf_len) -{ - const char *v3; // eax - char v4[20]; // [esp+0h] [ebp-14h] - - switch (error_code) { - CASE_ERROR(v3, DSERR_PRIOLEVELNEEDED); - CASE_ERROR(v3, DSERR_BADFORMAT); - CASE_ERROR(v3, DSERR_NODRIVER); - CASE_ERROR(v3, DSERR_ALREADYINITIALIZED); - CASE_ERROR(v3, DSERR_BUFFERLOST); - CASE_ERROR(v3, DS_OK); - CASE_ERROR(v3, DSERR_INVALIDCALL); - CASE_ERROR(v3, E_NOINTERFACE); - CASE_ERROR(v3, DSERR_NOAGGREGATION); - CASE_ERROR(v3, DSERR_OUTOFMEMORY); - CASE_ERROR(v3, DSERR_INVALIDPARAM); - CASE_ERROR(v3, DSERR_ALLOCATED); - CASE_ERROR(v3, DSERR_CONTROLUNAVAIL); - default: - strcpy(v4, "DSERR unknown 0x%x"); - sprintf(error_buf, v4, error_code); - return; - } - strncpy(error_buf, v3, error_buf_len); -} - -char *__cdecl GetLastErr() -{ - int v0; // eax - - v0 = GetLastError(); - return GetErr(v0); -} - -void TermMsg(char *pszFmt, ...) -{ - va_list arglist; // [esp+8h] [ebp+8h] - - va_start(arglist, pszFmt); - FreeDlg(); - if ( pszFmt ) - MsgBox(pszFmt, arglist); - init_cleanup(0); - exit(1); -} - -void __fastcall MsgBox(char *pszFmt, va_list va) -{ - char Text[256]; // [esp+0h] [ebp-100h] - - wvsprintf(Text, pszFmt, va); - if ( ghMainWnd ) - SetWindowPos(ghMainWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE); - MessageBox(ghMainWnd, Text, "ERROR", MB_TASKMODAL|MB_ICONHAND); -} - -void __cdecl FreeDlg() -{ - if ( terminating && cleanup_thread_id != GetCurrentThreadId() ) - Sleep(20000u); - terminating = 1; - cleanup_thread_id = GetCurrentThreadId(); - dx_cleanup(); - if ( (unsigned char)gbMaxPlayers > 1u ) - { - if ( SNetLeaveGame(3) ) - Sleep(2000u); - } - SNetDestroy(); - ShowCursor(1); -} -// 4B7A34: using guessed type int terminating; -// 4B7A38: using guessed type int cleanup_thread_id; -// 679660: using guessed type char gbMaxPlayers; - -void DrawDlg(char *pszFmt, ...) -{ - char text[256]; // [esp+0h] [ebp-100h] - va_list arglist; // [esp+10Ch] [ebp+Ch] - - va_start(arglist, pszFmt); - wvsprintf(text, pszFmt, arglist); - SDrawMessageBox(text, "Diablo", MB_TASKMODAL|MB_ICONEXCLAMATION); -} - -void __fastcall DDErrMsg(int error_code, int log_line_nr, char *log_file_path) -{ - int v3; // esi - char *v4; // eax - - v3 = log_line_nr; - if ( error_code ) - { - v4 = GetErr(error_code); - TermMsg("Direct draw error (%s:%d)\n%s", log_file_path, v3, v4); - } -} - -void __fastcall DSErrMsg(int error_code, int log_line_nr, char *log_file_path) -{ - int v3; // esi - char *v4; // eax - - v3 = log_line_nr; - if ( error_code ) - { - v4 = GetErr(error_code); - TermMsg("Direct sound error (%s:%d)\n%s", log_file_path, v3, v4); - } -} - -void __fastcall center_window(HWND hDlg) -{ - LONG v1; // esi - LONG v2; // edi - int v3; // ebx - char *v4; // eax - struct tagRECT Rect; // [esp+Ch] [ebp-1Ch] - int v6; // [esp+1Ch] [ebp-Ch] - HDC hdc; // [esp+20h] [ebp-8h] - HWND hWnd; // [esp+24h] [ebp-4h] - - hWnd = hDlg; - GetWindowRect(hDlg, &Rect); - v1 = Rect.right - Rect.left; - v2 = Rect.bottom - Rect.top; - hdc = GetDC(hWnd); - v6 = GetDeviceCaps(hdc, HORZRES); - v3 = GetDeviceCaps(hdc, VERTRES); - ReleaseDC(hWnd, hdc); - if ( !SetWindowPos(hWnd, HWND_TOP, (v6 - v1) / 2, (v3 - v2) / 2, 0, 0, SWP_NOZORDER|SWP_NOSIZE) ) - { - v4 = GetLastErr(); - TermMsg("center_window: %s", v4); - } -} - -void __fastcall ErrDlg(int template_id, int error_code, char *log_file_path, int log_line_nr) -{ - int v4; // ebx - int v5; // edi - char *v6; // esi - char *v7; // eax - char *v8; // eax - LPARAM dwInitParam[128]; // [esp+Ch] [ebp-200h] - - v4 = error_code; - v5 = template_id; - FreeDlg(); - v6 = log_file_path; - v7 = strrchr(log_file_path, '\\'); - if ( v7 ) - v6 = v7 + 1; - v8 = GetErr(v4); - wsprintf((LPSTR)dwInitParam, "%s\nat: %s line %d", v8, v6, log_line_nr); - if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(v5), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)dwInitParam) == -1 ) - TermMsg("ErrDlg: %d", v5); - TermMsg(0); -} - -BOOL __stdcall FuncDlg(HWND hDlg, UINT uMsg, WPARAM wParam, char *text) -{ - if ( uMsg == WM_INITDIALOG ) - { - TextDlg(hDlg, text); - } - else - { - if ( uMsg != WM_COMMAND ) - return 0; - if ( (_WORD)wParam == 1 ) - { - EndDialog(hDlg, 1); - } - else if ( (_WORD)wParam == 2 ) - { - EndDialog(hDlg, 0); - } - } - return 1; -} - -void __fastcall TextDlg(HWND hDlg, char *text) -{ - char *v2; // esi - HWND v3; // edi - - v2 = text; - v3 = hDlg; - center_window(hDlg); - if ( v2 ) - SetDlgItemText(v3, 1000, v2); -} - -void __fastcall ErrOkDlg(int template_id, int error_code, char *log_file_path, int log_line_nr) -{ - char *v4; // esi - int v5; // edi - unsigned short v6; // bx - char *v7; // eax - char *v8; // eax - LPARAM dwInitParam[128]; // [esp+Ch] [ebp-200h] - - v4 = log_file_path; - v5 = error_code; - v6 = template_id; - v7 = strrchr(log_file_path, '\\'); - if ( v7 ) - v4 = v7 + 1; - v8 = GetErr(v5); - wsprintf((LPSTR)dwInitParam, "%s\nat: %s line %d", v8, v4, log_line_nr); - DialogBoxParam(ghInst, MAKEINTRESOURCE(v6), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)dwInitParam); -} - -void __fastcall FileErrDlg(char *error) -{ - char *v1; // esi - - v1 = error; - FreeDlg(); - if ( !v1 ) - v1 = &empty_string; - if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG3), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1 ) - TermMsg("FileErrDlg"); - TermMsg(0); -} - -void __fastcall DiskFreeDlg(char *error) -{ - char *v1; // esi - - v1 = error; - FreeDlg(); - if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG7), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1 ) - TermMsg("DiskFreeDlg"); - TermMsg(0); -} - -bool __cdecl InsertCDDlg() -{ - int v0; // edi - - ShowCursor(1); - v0 = DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG9), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)&empty_string); - if ( v0 == -1 ) - TermMsg("InsertCDDlg"); - ShowCursor(0); - return v0 == 1; -} - -void __fastcall DirErrorDlg(char *error) -{ - char *v1; // esi - - v1 = error; - FreeDlg(); - if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG11), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1 ) - TermMsg("DirErrorDlg"); - TermMsg(0); -} +//HEADER_GOES_HERE + +#include "../types.h" + +// +Infinity after initialization of appfat.cpp. +float appfat_cpp_init_value; + +char sz_error_buf[256]; +int terminating; // weak +int cleanup_thread_id; // weak +char empty_string; + +// appfat_cpp_init initializes the C++ runtime of appfat.cpp. +struct appfat_cpp_init { + appfat_cpp_init() { + appfat_cpp_init_value = INFINITY; + } +} appfat_cpp_init; + +// delete overloads the delete operator. +void operator delete(void *ptr) { + if (ptr != NULL) { + SMemFree(ptr, "delete", -1, 0); + } +} + +char *__fastcall GetErrorStr(int error_code) +{ + int v1; // edi + unsigned int v2; // eax + signed int v4; // eax + char *i; // ecx + + v1 = error_code; + v2 = ((unsigned int)error_code >> 16) & 0x1FFF; + if ( v2 == 0x0878 ) + { + TraceErrorDS(error_code, sz_error_buf, 256); + } + else if ( v2 == 0x0876 ) + { + TraceErrorDD(error_code, sz_error_buf, 256); + } + else + { + if ( !SErrGetErrorStr(error_code, sz_error_buf, 256) && !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, v1, 0x400u, sz_error_buf, 0x100u, NULL) ) + wsprintf(sz_error_buf, "unknown error 0x%08x", v1); + } + v4 = strlen(sz_error_buf); + for ( i = &sz_error_buf[v4-1]; v4 > 0; *i = 0 ) + { + --v4; + --i; + if ( *i != '\r' && *i != '\n' ) + break; + } + return sz_error_buf; +} + +#define CASE_ERROR(v, errName) case errName: v = #errName; break; + +void __fastcall TraceErrorDD(int error_code, char *error_buf, int error_buf_len) +{ + const char *v3; // eax + char v4[20]; // [esp+0h] [ebp-14h] + + switch (error_code) { + CASE_ERROR(v3, DDERR_CANTPAGEUNLOCK); + CASE_ERROR(v3, DDERR_NOTPAGELOCKED); + CASE_ERROR(v3, DD_OK); + CASE_ERROR(v3, DDERR_CANTPAGELOCK); + CASE_ERROR(v3, DDERR_BLTFASTCANTCLIP); + CASE_ERROR(v3, DDERR_NOBLTHW); + CASE_ERROR(v3, DDERR_NODDROPSHW); + CASE_ERROR(v3, DDERR_OVERLAYNOTVISIBLE); + CASE_ERROR(v3, DDERR_NOOVERLAYDEST); + CASE_ERROR(v3, DDERR_INVALIDPOSITION); + CASE_ERROR(v3, DDERR_NOTAOVERLAYSURFACE); + CASE_ERROR(v3, DDERR_EXCLUSIVEMODEALREADYSET); + CASE_ERROR(v3, DDERR_NOTFLIPPABLE); + CASE_ERROR(v3, DDERR_CANTDUPLICATE); + CASE_ERROR(v3, DDERR_NOTLOCKED); + CASE_ERROR(v3, DDERR_CANTCREATEDC); + CASE_ERROR(v3, DDERR_NODC); + CASE_ERROR(v3, DDERR_WRONGMODE); + CASE_ERROR(v3, DDERR_IMPLICITLYCREATED); + CASE_ERROR(v3, DDERR_NOTPALETTIZED); + CASE_ERROR(v3, DDERR_NOMIPMAPHW); + CASE_ERROR(v3, DDERR_INVALIDSURFACETYPE); + CASE_ERROR(v3, DDERR_DCALREADYCREATED); + CASE_ERROR(v3, DDERR_NOPALETTEHW); + CASE_ERROR(v3, DDERR_DIRECTDRAWALREADYCREATED); + CASE_ERROR(v3, DDERR_NODIRECTDRAWHW); + CASE_ERROR(v3, DDERR_PRIMARYSURFACEALREADYEXISTS); + CASE_ERROR(v3, DDERR_NOEMULATION); + CASE_ERROR(v3, DDERR_REGIONTOOSMALL); + CASE_ERROR(v3, DDERR_CLIPPERISUSINGHWND); + CASE_ERROR(v3, DDERR_NOCLIPPERATTACHED); + CASE_ERROR(v3, DDERR_NOHWND); + CASE_ERROR(v3, DDERR_HWNDSUBCLASSED); + CASE_ERROR(v3, DDERR_HWNDALREADYSET); + CASE_ERROR(v3, DDERR_NOPALETTEATTACHED); + CASE_ERROR(v3, DDERR_INVALIDDIRECTDRAWGUID); + CASE_ERROR(v3, DDERR_UNSUPPORTEDFORMAT); + CASE_ERROR(v3, DDERR_UNSUPPORTEDMASK); + CASE_ERROR(v3, DDERR_VERTICALBLANKINPROGRESS); + CASE_ERROR(v3, DDERR_WASSTILLDRAWING); + CASE_ERROR(v3, DDERR_XALIGN); + CASE_ERROR(v3, DDERR_TOOBIGWIDTH); + CASE_ERROR(v3, DDERR_CANTLOCKSURFACE); + CASE_ERROR(v3, DDERR_SURFACEISOBSCURED); + CASE_ERROR(v3, DDERR_SURFACELOST); + CASE_ERROR(v3, DDERR_SURFACENOTATTACHED); + CASE_ERROR(v3, DDERR_TOOBIGHEIGHT); + CASE_ERROR(v3, DDERR_TOOBIGSIZE); + CASE_ERROR(v3, DDERR_SURFACEBUSY); + CASE_ERROR(v3, DDERR_OVERLAYCOLORKEYONLYONEACTIVE); + CASE_ERROR(v3, DDERR_PALETTEBUSY); + CASE_ERROR(v3, DDERR_COLORKEYNOTSET); + CASE_ERROR(v3, DDERR_SURFACEALREADYATTACHED); + CASE_ERROR(v3, DDERR_SURFACEALREADYDEPENDENT); + CASE_ERROR(v3, DDERR_OVERLAYCANTCLIP); + CASE_ERROR(v3, DDERR_NOVSYNCHW); + CASE_ERROR(v3, DDERR_NOZBUFFERHW); + CASE_ERROR(v3, DDERR_NOZOVERLAYHW); + CASE_ERROR(v3, DDERR_OUTOFCAPS); + CASE_ERROR(v3, DDERR_OUTOFVIDEOMEMORY); + CASE_ERROR(v3, DDERR_NOTEXTUREHW); + CASE_ERROR(v3, DDERR_NOROTATIONHW); + CASE_ERROR(v3, DDERR_NOSTRETCHHW); + CASE_ERROR(v3, DDERR_NOT4BITCOLOR); + CASE_ERROR(v3, DDERR_NOT4BITCOLORINDEX); + CASE_ERROR(v3, DDERR_NOT8BITCOLOR); + CASE_ERROR(v3, DDERR_NORASTEROPHW); + CASE_ERROR(v3, DDERR_NOEXCLUSIVEMODE); + CASE_ERROR(v3, DDERR_NOFLIPHW); + CASE_ERROR(v3, DDERR_NOGDI); + CASE_ERROR(v3, DDERR_NOMIRRORHW); + CASE_ERROR(v3, DDERR_NOTFOUND); + CASE_ERROR(v3, DDERR_NOOVERLAYHW); + CASE_ERROR(v3, DDERR_NOCOLORKEYHW); + CASE_ERROR(v3, DDERR_NOALPHAHW); + CASE_ERROR(v3, DDERR_NOCLIPLIST); + CASE_ERROR(v3, DDERR_NOCOLORCONVHW); + CASE_ERROR(v3, DDERR_NOCOOPERATIVELEVELSET); + CASE_ERROR(v3, DDERR_NOCOLORKEY); + CASE_ERROR(v3, DDERR_NO3D); + CASE_ERROR(v3, DDERR_INVALIDMODE); + CASE_ERROR(v3, DDERR_INVALIDOBJECT); + CASE_ERROR(v3, DDERR_INVALIDPIXELFORMAT); + CASE_ERROR(v3, DDERR_INVALIDRECT); + CASE_ERROR(v3, DDERR_LOCKEDSURFACES); + CASE_ERROR(v3, DDERR_INVALIDCLIPLIST); + CASE_ERROR(v3, DDERR_CURRENTLYNOTAVAIL); + CASE_ERROR(v3, DDERR_EXCEPTION); + CASE_ERROR(v3, DDERR_HEIGHTALIGN); + CASE_ERROR(v3, DDERR_INCOMPATIBLEPRIMARY); + CASE_ERROR(v3, DDERR_INVALIDCAPS); + CASE_ERROR(v3, DDERR_CANNOTDETACHSURFACE); + CASE_ERROR(v3, DDERR_UNSUPPORTED); + CASE_ERROR(v3, DDERR_GENERIC); + CASE_ERROR(v3, DDERR_OUTOFMEMORY); + CASE_ERROR(v3, DDERR_INVALIDPARAMS); + CASE_ERROR(v3, DDERR_ALREADYINITIALIZED); + CASE_ERROR(v3, DDERR_CANNOTATTACHSURFACE); + default: + strcpy(v4, "DDERR unknown 0x%x"); + sprintf(error_buf, v4, error_code); + return; + } + strncpy(error_buf, v3, error_buf_len); +} + +void __fastcall TraceErrorDS(int error_code, char *error_buf, int error_buf_len) +{ + const char *v3; // eax + char v4[20]; // [esp+0h] [ebp-14h] + + switch (error_code) { + CASE_ERROR(v3, DSERR_PRIOLEVELNEEDED); + CASE_ERROR(v3, DSERR_BADFORMAT); + CASE_ERROR(v3, DSERR_NODRIVER); + CASE_ERROR(v3, DSERR_ALREADYINITIALIZED); + CASE_ERROR(v3, DSERR_BUFFERLOST); + CASE_ERROR(v3, DS_OK); + CASE_ERROR(v3, DSERR_INVALIDCALL); + CASE_ERROR(v3, E_NOINTERFACE); + CASE_ERROR(v3, DSERR_NOAGGREGATION); + CASE_ERROR(v3, DSERR_OUTOFMEMORY); + CASE_ERROR(v3, DSERR_INVALIDPARAM); + CASE_ERROR(v3, DSERR_ALLOCATED); + CASE_ERROR(v3, DSERR_CONTROLUNAVAIL); + default: + strcpy(v4, "DSERR unknown 0x%x"); + sprintf(error_buf, v4, error_code); + return; + } + strncpy(error_buf, v3, error_buf_len); +} + +char *__cdecl TraceLastError() +{ + int v0; // eax + + v0 = GetLastError(); + return GetErrorStr(v0); +} + +void TermMsg(char *pszFmt, ...) +{ + va_list arglist; // [esp+8h] [ebp+8h] + + va_start(arglist, pszFmt); + FreeDlg(); + if ( pszFmt ) + MsgBox(pszFmt, arglist); + init_cleanup(0); + exit(1); +} + +void __fastcall MsgBox(char *pszFmt, va_list va) +{ + char Text[256]; // [esp+0h] [ebp-100h] + + wvsprintf(Text, pszFmt, va); + if ( ghMainWnd ) + SetWindowPos(ghMainWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE); + MessageBox(ghMainWnd, Text, "ERROR", MB_TASKMODAL|MB_ICONHAND); +} + +void __cdecl FreeDlg() +{ + if ( terminating && cleanup_thread_id != GetCurrentThreadId() ) + Sleep(20000u); + terminating = 1; + cleanup_thread_id = GetCurrentThreadId(); + dx_cleanup(); + if ( (unsigned char)gbMaxPlayers > 1u ) + { + if ( SNetLeaveGame(3) ) + Sleep(2000u); + } + SNetDestroy(); + ShowCursor(1); +} +// 4B7A34: using guessed type int terminating; +// 4B7A38: using guessed type int cleanup_thread_id; +// 679660: using guessed type char gbMaxPlayers; + +void DrawDlg(char *pszFmt, ...) +{ + char text[256]; // [esp+0h] [ebp-100h] + va_list arglist; // [esp+10Ch] [ebp+Ch] + + va_start(arglist, pszFmt); + wvsprintf(text, pszFmt, arglist); + SDrawMessageBox(text, "Diablo", MB_TASKMODAL|MB_ICONEXCLAMATION); +} + +void __fastcall DDErrMsg(int error_code, int log_line_nr, char *log_file_path) +{ + int v3; // esi + char *v4; // eax + + v3 = log_line_nr; + if ( error_code ) + { + v4 = GetErrorStr(error_code); + TermMsg("Direct draw error (%s:%d)\n%s", log_file_path, v3, v4); + } +} + +void __fastcall DSErrMsg(int error_code, int log_line_nr, char *log_file_path) +{ + int v3; // esi + char *v4; // eax + + v3 = log_line_nr; + if ( error_code ) + { + v4 = GetErrorStr(error_code); + TermMsg("Direct sound error (%s:%d)\n%s", log_file_path, v3, v4); + } +} + +void __fastcall center_window(HWND hDlg) +{ + LONG v1; // esi + LONG v2; // edi + int v3; // ebx + char *v4; // eax + struct tagRECT Rect; // [esp+Ch] [ebp-1Ch] + int v6; // [esp+1Ch] [ebp-Ch] + HDC hdc; // [esp+20h] [ebp-8h] + HWND hWnd; // [esp+24h] [ebp-4h] + + hWnd = hDlg; + GetWindowRect(hDlg, &Rect); + v1 = Rect.right - Rect.left; + v2 = Rect.bottom - Rect.top; + hdc = GetDC(hWnd); + v6 = GetDeviceCaps(hdc, HORZRES); + v3 = GetDeviceCaps(hdc, VERTRES); + ReleaseDC(hWnd, hdc); + if ( !SetWindowPos(hWnd, HWND_TOP, (v6 - v1) / 2, (v3 - v2) / 2, 0, 0, SWP_NOZORDER|SWP_NOSIZE) ) + { + v4 = TraceLastError(); + TermMsg("center_window: %s", v4); + } +} + +void __fastcall ErrDlg(int template_id, int error_code, char *log_file_path, int log_line_nr) +{ + int v4; // ebx + int v5; // edi + char *v6; // esi + char *v7; // eax + char *v8; // eax + LPARAM dwInitParam[128]; // [esp+Ch] [ebp-200h] + + v4 = error_code; + v5 = template_id; + FreeDlg(); + v6 = log_file_path; + v7 = strrchr(log_file_path, '\\'); + if ( v7 ) + v6 = v7 + 1; + v8 = GetErrorStr(v4); + wsprintf((LPSTR)dwInitParam, "%s\nat: %s line %d", v8, v6, log_line_nr); + if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(v5), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)dwInitParam) == -1 ) + TermMsg("ErrDlg: %d", v5); + TermMsg(0); +} + +BOOL __stdcall FuncDlg(HWND hDlg, UINT uMsg, WPARAM wParam, char *text) +{ + if ( uMsg == WM_INITDIALOG ) + { + TextDlg(hDlg, text); + } + else + { + if ( uMsg != WM_COMMAND ) + return 0; + if ( (_WORD)wParam == 1 ) + { + EndDialog(hDlg, 1); + } + else if ( (_WORD)wParam == 2 ) + { + EndDialog(hDlg, 0); + } + } + return 1; +} + +void __fastcall TextDlg(HWND hDlg, char *text) +{ + char *v2; // esi + HWND v3; // edi + + v2 = text; + v3 = hDlg; + center_window(hDlg); + if ( v2 ) + SetDlgItemText(v3, 1000, v2); +} + +void __fastcall ErrOkDlg(int template_id, int error_code, char *log_file_path, int log_line_nr) +{ + char *v4; // esi + int v5; // edi + unsigned short v6; // bx + char *v7; // eax + char *v8; // eax + LPARAM dwInitParam[128]; // [esp+Ch] [ebp-200h] + + v4 = log_file_path; + v5 = error_code; + v6 = template_id; + v7 = strrchr(log_file_path, '\\'); + if ( v7 ) + v4 = v7 + 1; + v8 = GetErrorStr(v5); + wsprintf((LPSTR)dwInitParam, "%s\nat: %s line %d", v8, v4, log_line_nr); + DialogBoxParam(ghInst, MAKEINTRESOURCE(v6), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)dwInitParam); +} + +void __fastcall FileErrDlg(char *error) +{ + char *v1; // esi + + v1 = error; + FreeDlg(); + if ( !v1 ) + v1 = &empty_string; + if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG3), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1 ) + TermMsg("FileErrDlg"); + TermMsg(0); +} + +void __fastcall DiskFreeDlg(char *error) +{ + char *v1; // esi + + v1 = error; + FreeDlg(); + if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG7), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1 ) + TermMsg("DiskFreeDlg"); + TermMsg(0); +} + +bool __cdecl InsertCDDlg() +{ + int v0; // edi + + ShowCursor(1); + v0 = DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG9), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)&empty_string); + if ( v0 == -1 ) + TermMsg("InsertCDDlg"); + ShowCursor(0); + return v0 == 1; +} + +void __fastcall DirErrorDlg(char *error) +{ + char *v1; // esi + + v1 = error; + FreeDlg(); + if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG11), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1 ) + TermMsg("DirErrorDlg"); + TermMsg(0); +} diff --git a/Source/appfat.h b/Source/appfat.h index 5d9b40db8..d0542b40e 100644 --- a/Source/appfat.h +++ b/Source/appfat.h @@ -7,10 +7,10 @@ extern int terminating; // weak extern int cleanup_thread_id; // weak extern char empty_string; -char *__fastcall GetErr(int error_code); -void __fastcall GetDDErr(int error_code, char *error_buf, int error_buf_len); -void __fastcall GetDSErr(int error_code, char *error_buf, int error_buf_len); -char *__cdecl GetLastErr(); +char *__fastcall GetErrorStr(int error_code); +void __fastcall TraceErrorDD(int error_code, char *error_buf, int error_buf_len); +void __fastcall TraceErrorDS(int error_code, char *error_buf, int error_buf_len); +char *__cdecl TraceLastError(); void TermMsg(char *pszFmt, ...); void __fastcall MsgBox(char *pszFmt, va_list va); void __cdecl FreeDlg(); diff --git a/Source/control.cpp b/Source/control.cpp index c3bc5b17e..70046ac57 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -2887,7 +2887,7 @@ void __cdecl CheckSBook() v0 = MouseY; } } - if ( v1 >= 327 && v1 < 633 && v0 >= 320 && v0 < 349 ) + if ( v1 >= 327 && v1 < 633 && v0 >= 320 && v0 < 349 ) /// BUGFIX: change `< 633` to `< 631` sbooktab = (v1 - 327) / 76; } // 4B8950: using guessed type int sbooktab; diff --git a/Source/dthread.cpp b/Source/dthread.cpp index d978e8f12..7fbc66050 100644 --- a/Source/dthread.cpp +++ b/Source/dthread.cpp @@ -106,14 +106,14 @@ void __cdecl dthread_start() sghWorkToDoEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if ( !sghWorkToDoEvent ) { - v0 = GetLastErr(); + v0 = TraceLastError(); TermMsg("dthread:1\n%s", v0); } byte_52A508 = 1; sghThread = (HANDLE)_beginthreadex(NULL, 0, dthread_handler, NULL, 0, &glpDThreadId); if ( sghThread == (HANDLE)-1 ) { - v1 = GetLastErr(); + v1 = TraceLastError(); TermMsg("dthread2:\n%s", v1); } } @@ -132,7 +132,7 @@ unsigned int __stdcall dthread_handler(void *a1) { if ( !sgpInfoHead && WaitForSingleObject(sghWorkToDoEvent, 0xFFFFFFFF) == -1 ) { - v1 = GetLastErr(); + v1 = TraceLastError(); TermMsg("dthread4:\n%s", v1); } EnterCriticalSection(&sgMemCrit); @@ -174,7 +174,7 @@ void __cdecl dthread_cleanup() { if ( WaitForSingleObject(sghThread, 0xFFFFFFFF) == -1 ) { - v0 = GetLastErr(); + v0 = TraceLastError(); TermMsg("dthread3:\n(%s)", v0); } CloseHandle(sghThread); diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index e2377d7a0..4ae202a61 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -12,7 +12,7 @@ bool save_archive_open; // weak const int mpqapi_inf = 0x7F800000; // weak -//note: 32872 = 32768 + 104 (sizeof(TMPQHEADER)) +//note: 32872 = 32768 + 104 (sizeof(_FILEHEADER)) /* data */ @@ -551,7 +551,7 @@ bool __fastcall mpqapi_open_archive(char *pszArchive, bool hidden, int dwChar) / int v10; // eax char *lpFileName; // [esp+10h] [ebp-70h] DWORD dwTemp; // [esp+14h] [ebp-6Ch] - TMPQHeader fhdr; // [esp+18h] [ebp-68h] + _FILEHEADER fhdr; // [esp+18h] [ebp-68h] v3 = pszArchive; v4 = hidden; @@ -581,7 +581,7 @@ LABEL_15: } sgpBlockTbl = (_BLOCKENTRY *)DiabloAllocPtr(0x8000); memset(sgpBlockTbl, 0, 0x8000u); - if ( fhdr.dwBlockTableSize ) + if ( fhdr.blockcount ) { if ( SetFilePointer(sghArchive, 104, NULL, FILE_BEGIN) == -1 || !ReadFile(sghArchive, sgpBlockTbl, 0x8000u, &dwTemp, NULL) ) @@ -593,7 +593,7 @@ LABEL_15: } sgpHashTbl = (_HASHENTRY *)DiabloAllocPtr(0x8000); memset(sgpHashTbl, 255, 0x8000u); - if ( fhdr.dwHashTableSize ) + if ( fhdr.hashcount ) { if ( SetFilePointer(sghArchive, 32872, NULL, FILE_BEGIN) == -1 || !ReadFile(sghArchive, sgpHashTbl, 0x8000u, &dwTemp, NULL) ) @@ -610,10 +610,10 @@ LABEL_15: // 65AB14: using guessed type char save_archive_open; // 679660: using guessed type char gbMaxPlayers; -bool __fastcall mpqapi_parse_archive_header(TMPQHeader *pHdr, int *pdwNextFileStart) // ParseMPQHeader +bool __fastcall mpqapi_parse_archive_header(_FILEHEADER *pHdr, int *pdwNextFileStart) // ParseMPQHeader { int *v2; // ebp - TMPQHeader *v3; // esi + _FILEHEADER *v3; // esi DWORD v4; // eax DWORD v5; // edi DWORD NumberOfBytesRead; // [esp+10h] [ebp-4h] @@ -627,23 +627,23 @@ bool __fastcall mpqapi_parse_archive_header(TMPQHeader *pHdr, int *pdwNextFileSt || v4 < 0x68 || !ReadFile(sghArchive, v3, 0x68u, &NumberOfBytesRead, NULL) || NumberOfBytesRead != 104 - || v3->dwID != '\x1AQPM' - || v3->dwHeaderSize != 32 - || v3->wFormatVersion > 0u - || v3->wSectorSize != 3 - || v3->dwArchiveSize != v5 - || v3->dwHashTablePos != 32872 - || v3->dwBlockTablePos != 104 - || v3->dwHashTableSize != 2048 - || v3->dwBlockTableSize != 2048 ) + || v3->signature != '\x1AQPM' + || v3->headersize != 32 + || v3->version > 0u + || v3->sectorsizeid != 3 + || v3->filesize != v5 + || v3->hashoffset != 32872 + || v3->blockoffset != 104 + || v3->hashcount != 2048 + || v3->blockcount != 2048 ) { if ( SetFilePointer(sghArchive, 0, NULL, FILE_BEGIN) == -1 || !SetEndOfFile(sghArchive) ) return 0; memset(v3, 0, 0x68u); - v3->dwID = '\x1AQPM'; - v3->dwHeaderSize = 32; - v3->wSectorSize = 3; - v3->wFormatVersion = 0; + v3->signature = '\x1AQPM'; + v3->headersize = 32; + v3->sectorsizeid = 3; + v3->version = 0; *v2 = 0x10068; save_archive_modified = 1; save_archive_open = 1; @@ -738,19 +738,19 @@ void __fastcall mpqapi_flush_and_close(char *pszArchive, bool bFree, int dwChar) bool __cdecl mpqapi_write_header() // WriteMPQHeader { bool result; // al - TMPQHeader fhdr; // [esp+8h] [ebp-6Ch] + _FILEHEADER fhdr; // [esp+8h] [ebp-6Ch] DWORD NumberOfBytesWritten; // [esp+70h] [ebp-4h] memset(&fhdr, 0, 0x68u); - fhdr.dwID = '\x1AQPM'; - fhdr.dwHeaderSize = 32; - fhdr.dwArchiveSize = GetFileSize(sghArchive, 0); - fhdr.wFormatVersion = 0; - fhdr.wSectorSize = 3; - fhdr.dwHashTablePos = 32872; - fhdr.dwBlockTablePos = 104; - fhdr.dwHashTableSize = 2048; - fhdr.dwBlockTableSize = 2048; + fhdr.signature = '\x1AQPM'; + fhdr.headersize = 32; + fhdr.filesize = GetFileSize(sghArchive, 0); + fhdr.version = 0; + fhdr.sectorsizeid = 3; + fhdr.hashoffset = 32872; + fhdr.blockoffset = 104; + fhdr.hashcount = 2048; + fhdr.blockcount = 2048; if ( SetFilePointer(sghArchive, 0, NULL, FILE_BEGIN) != -1 && WriteFile(sghArchive, &fhdr, 0x68u, &NumberOfBytesWritten, 0) ) result = NumberOfBytesWritten == 104; else diff --git a/Source/mpqapi.h b/Source/mpqapi.h index 73a8badee..b0dea1486 100644 --- a/Source/mpqapi.h +++ b/Source/mpqapi.h @@ -30,7 +30,7 @@ int __fastcall mpqapi_find_free_block(int size, int *block_size); void __fastcall mpqapi_rename(char *pszOld, char *pszNew); bool __fastcall mpqapi_has_file(char *pszName); bool __fastcall mpqapi_open_archive(char *pszArchive, bool hidden, int dwChar); -bool __fastcall mpqapi_parse_archive_header(TMPQHeader *pHdr, int *pdwNextFileStart); +bool __fastcall mpqapi_parse_archive_header(_FILEHEADER *pHdr, int *pdwNextFileStart); void __fastcall mpqapi_close_archive(char *pszArchive, bool bFree, int dwChar); void __fastcall mpqapi_store_modified_time(char *pszArchive, int dwChar); void __fastcall mpqapi_flush_and_close(char *pszArchive, bool bFree, int dwChar); diff --git a/Source/multi.cpp b/Source/multi.cpp index 86341afcc..571698a00 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -740,7 +740,7 @@ char __fastcall multi_event_handler(int a1) v4 = (int)v2(event_types[v3], multi_handle_events); if ( !v4 && v1 ) { - v5 = GetLastErr(); + v5 = TraceLastError(); TermMsg("SNetRegisterEventHandler:\n%s", v5); } ++v3; @@ -1002,7 +1002,7 @@ int __fastcall multi_init_single(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA //_LOBYTE(v5) = SNetCreateGame("local", "local", "local", 0, (char *)&sgGameInitInfo.dwSeed, 8, 1, "local", "local", (int *)&ui_info); if ( !SNetCreateGame("local", "local", "local", 0, (char *)&sgGameInitInfo.dwSeed, 8, 1, "local", "local", (int *)&ui_info) ) { - v6 = GetLastErr(); + v6 = TraceLastError(); TermMsg("SNetCreateGame1:\n%s", v6); } myplr = 0; diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 9162268bc..04851f922 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -75,7 +75,7 @@ void __fastcall nthread_terminate_game(char *pszFcn) } else { - v3 = GetLastErr(); + v3 = TraceLastError(); TermMsg("%s:\n%s", v1, v3); } } @@ -193,7 +193,7 @@ void __fastcall nthread_start(bool set_turn_upper_bit) caps.size = 36; if ( !SNetGetProviderCaps(&caps) ) { - v3 = GetLastErr(); + v3 = TraceLastError(); TermMsg("SNetGetProviderCaps:\n%s", v3); } gdwTurnsInTransit = caps.defaultturnsintransit; @@ -232,7 +232,7 @@ void __fastcall nthread_start(bool set_turn_upper_bit) sghThread = (HANDLE)_beginthreadex(NULL, 0, nthread_handler, NULL, 0, &glpNThreadId); if ( sghThread == (HANDLE)-1 ) { - v6 = GetLastErr(); + v6 = TraceLastError(); TermMsg("nthread2:\n%s", v6); } SetThreadPriority(sghThread, THREAD_PRIORITY_HIGHEST); @@ -296,7 +296,7 @@ void __cdecl nthread_cleanup() LeaveCriticalSection(&sgMemCrit); if ( WaitForSingleObject(sghThread, 0xFFFFFFFF) == -1 ) { - v0 = GetLastErr(); + v0 = TraceLastError(); TermMsg("nthread3:\n(%s)", v0); } CloseHandle(sghThread); diff --git a/Source/player.cpp b/Source/player.cpp index 52b1e4499..95fc53d20 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -2116,40 +2116,24 @@ LABEL_28: void __fastcall SyncPlrKill(int pnum, int earflag) { - int v2; // esi - int v3; // ebx - int v4; // edx - int v5; // eax + if ( plr[pnum]._pHitPoints == 0 && currlevel == 0 ) { + SetPlayerHitPoints(pnum, 64); + return; + } - v2 = pnum; - v3 = earflag; - if ( plr[pnum]._pHitPoints || currlevel ) - { - v4 = 0; - if ( nummissiles <= 0 ) - { -LABEL_9: - SetPlayerHitPoints(pnum, 0); - StartPlayerKill(v2, v3); - } - else - { - while ( 1 ) - { - v5 = missileactive[v4]; - if ( missile[v5]._mitype == 13 && missile[v5]._misource == pnum && !missile[v5]._miDelFlag ) - break; - if ( ++v4 >= nummissiles ) - goto LABEL_9; + for ( int i = 0; i < nummissiles; i++ ) { + int ma = missileactive[i]; + if ( missile[ma]._mitype == MIS_MANASHIELD && missile[ma]._misource == pnum && missile[ma]._miDelFlag == 0 ) { + if ( earflag != -1 ) { + missile[ma]._miVar8 = earflag; } - if ( v3 != -1 ) - missile[missileactive[v4]]._miVar8 = v3; + + return; } } - else - { - SetPlayerHitPoints(pnum, 64); - } + + SetPlayerHitPoints(pnum, 0); + StartPlayerKill(pnum, earflag); } void __fastcall RemovePlrMissiles(int pnum) diff --git a/Source/wave.cpp b/Source/wave.cpp index c73d001fa..cbb1fb3c8 100644 --- a/Source/wave.cpp +++ b/Source/wave.cpp @@ -137,7 +137,7 @@ int __fastcall LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx) return v3; } -void *__fastcall AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, unsigned int a3) +void *__fastcall AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, unsigned int dwPos) { MEMFILE *v3; // esi HANDLE v4; // edi @@ -151,8 +151,8 @@ void *__fastcall AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, unsigned int v5 = WGetFileSize(v4, 0); v6 = 4096; v3->end = v5; - if ( a3 > 0x1000 ) - v6 = a3; + if ( dwPos > 0x1000 ) + v6 = dwPos; v3->buf_len = v6; if ( v6 >= v5 ) v6 = v5; diff --git a/Source/wave.h b/Source/wave.h index 437e77f59..cc8211d11 100644 --- a/Source/wave.h +++ b/Source/wave.h @@ -13,7 +13,7 @@ int __fastcall WOpenFile(char *dwInitParam, HANDLE *phsFile, int a3); char __fastcall WReadFile(HANDLE hsFile, char *buf, int a3); int __fastcall WSetFilePointer(HANDLE file1, int offset, HANDLE file2, int whence); int __fastcall LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx); -void *__fastcall AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, unsigned int a3); +void *__fastcall AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, unsigned int dwPos); void __fastcall FreeMemFile(MEMFILE *pMemFile); int __fastcall ReadWaveFile(MEMFILE *pMemFile, WAVEFORMATEX *pwfx, int *a3); int __fastcall ReadMemFile(MEMFILE *pMemFile, void *lpBuf, size_t a3); diff --git a/structs.h b/structs.h index 1479b4160..0b2062aab 100644 --- a/structs.h +++ b/structs.h @@ -1547,18 +1547,18 @@ struct TMsg // mpqapi ////////////////////////////////////////////////// -struct TMPQHeader // _FILEHEADER -{ - int dwID; - int dwHeaderSize; - int dwArchiveSize; - short wFormatVersion; - short wSectorSize; - int dwHashTablePos; - int dwBlockTablePos; - int dwHashTableSize; - int dwBlockTableSize; - char field_20[72]; +struct _FILEHEADER +{ + int signature; + int headersize; + int filesize; + short version; + short sectorsizeid; + int hashoffset; + int blockoffset; + int hashcount; + int blockcount; + char pad[72]; }; struct _HASHENTRY