Browse Source

Format debug related code

pull/25/head
Anders Jenbo 8 years ago
parent
commit
fcc4e19287
  1. 657
      Source/appfat.cpp
  2. 2
      Source/appfat.h
  3. 308
      Source/debug.cpp
  4. 265
      Source/error.cpp
  5. 4
      Source/fault.h
  6. 339
      Source/logging.cpp
  7. 6
      Source/logging.h
  8. 2
      types.h

657
Source/appfat.cpp

@ -6,243 +6,241 @@
float appfat_cpp_init_value;
char sz_error_buf[256];
int terminating; // weak
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()
{
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);
}
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;
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;
#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);
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);
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
int v0; // eax
v0 = GetLastError();
return GetErrorStr(v0);
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);
va_end(arglist);
init_cleanup(0);
exit(1);
va_list arglist; // [esp+8h] [ebp+8h]
va_start(arglist, pszFmt);
FreeDlg();
if (pszFmt)
MsgBox(pszFmt, arglist);
va_end(arglist);
init_cleanup(0);
exit(1);
}
void __fastcall MsgBox(char *pszFmt, va_list va)
{
char Text[256]; // [esp+0h] [ebp-100h]
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);
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);
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;
@ -250,187 +248,178 @@ void __cdecl FreeDlg()
void DrawDlg(char *pszFmt, ...)
{
char text[256]; // [esp+0h] [ebp-100h]
va_list arglist; // [esp+10Ch] [ebp+Ch]
char text[256]; // [esp+0h] [ebp-100h]
va_list arglist; // [esp+10Ch] [ebp+Ch]
va_start(arglist, pszFmt);
wvsprintf(text, pszFmt, arglist);
va_end(arglist);
SDrawMessageBox(text, "Diablo", MB_TASKMODAL|MB_ICONEXCLAMATION);
va_start(arglist, pszFmt);
wvsprintf(text, pszFmt, arglist);
va_end(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);
}
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);
}
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);
}
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);
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;
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);
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);
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(const char *error)
{
const 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);
const 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
char *v1; // esi
v1 = error;
FreeDlg();
if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG7), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1 )
TermMsg("DiskFreeDlg");
TermMsg(0);
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;
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
char *v1; // esi
v1 = error;
FreeDlg();
if ( DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG11), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1 )
TermMsg("DirErrorDlg");
TermMsg(0);
v1 = error;
FreeDlg();
if (DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_DIALOG11), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)v1) == -1)
TermMsg("DirErrorDlg");
TermMsg(0);
}

2
Source/appfat.h

@ -3,7 +3,7 @@
#define __APPFAT_H__
extern char sz_error_buf[256];
extern int terminating; // weak
extern int terminating; // weak
extern int cleanup_thread_id; // weak
extern char empty_string;

308
Source/debug.cpp

@ -22,218 +22,206 @@ void __cdecl FreeDebugGFX()
void __cdecl CheckDungeonClear()
{
int i;
int j;
for(i = 0; i < MAXDUNX; i++)
{
for(j = 0; j < MAXDUNY; j++)
{
if ( dMonster[i][j] )
TermMsg("Monsters not cleared");
if ( dPlayer[i][j] )
TermMsg("Players not cleared");
dMonsDbg[currlevel][i][j] = dFlags[i][j] & DFLAG_VISIBLE;
dFlagDbg[currlevel][i][j] = dFlags[i][j] & DFLAG_POPULATED;
}
}
int i;
int j;
for (i = 0; i < MAXDUNX; i++) {
for (j = 0; j < MAXDUNY; j++) {
if (dMonster[i][j])
TermMsg("Monsters not cleared");
if (dPlayer[i][j])
TermMsg("Players not cleared");
dMonsDbg[currlevel][i][j] = dFlags[i][j] & DFLAG_VISIBLE;
dFlagDbg[currlevel][i][j] = dFlags[i][j] & DFLAG_POPULATED;
}
}
}
#ifdef _DEBUG
void __cdecl GiveGoldCheat()
{
int i; // esi
int ni; // ebp
for(i = 0; i < 40; i++)
{
if ( !plr[myplr].InvGrid[i] )
{
ni = plr[myplr]._pNumInv++;
SetPlrHandItem(&plr[myplr].InvList[ni], IDI_GOLD);
GetPlrHandSeed(&plr[myplr].InvList[ni]);
plr[myplr].InvList[ni]._ivalue = 5000;
plr[myplr].InvList[ni]._iCurs = 6;
plr[myplr]._pGold += 5000;
plr[myplr].InvGrid[i] = plr[myplr]._pNumInv;
}
}
int i; // esi
int ni; // ebp
for (i = 0; i < 40; i++) {
if (!plr[myplr].InvGrid[i]) {
ni = plr[myplr]._pNumInv++;
SetPlrHandItem(&plr[myplr].InvList[ni], IDI_GOLD);
GetPlrHandSeed(&plr[myplr].InvList[ni]);
plr[myplr].InvList[ni]._ivalue = 5000;
plr[myplr].InvList[ni]._iCurs = 6;
plr[myplr]._pGold += 5000;
plr[myplr].InvGrid[i] = plr[myplr]._pNumInv;
}
}
}
void __cdecl StoresCheat()
{
int i; // eax
int i; // eax
numpremium = 0;
numpremium = 0;
for(i = 0; i < 6; i++)
premiumitem[i]._itype = -1;
for (i = 0; i < 6; i++)
premiumitem[i]._itype = -1;
SpawnPremium(30);
SpawnPremium(30);
for(i = 0; i < 20; i++)
witchitem[i]._itype = -1;
for (i = 0; i < 20; i++)
witchitem[i]._itype = -1;
SpawnWitch(30);
SpawnWitch(30);
}
void __cdecl TakeGoldCheat()
{
int i; // esi
char ig; // cl
for(i = 0; i < 40; i++)
{
ig = plr[myplr].InvGrid[i];
if ( ig > 0 && plr[myplr].InvList[ig - 1]._itype == ITYPE_GOLD )
RemoveInvItem(myplr, ig - 1);
}
for(i = 0; i < MAXBELTITEMS; i++)
{
if ( plr[myplr].SpdList[i]._itype == ITYPE_GOLD )
plr[myplr].SpdList[i]._itype = -1;
}
plr[myplr]._pGold = 0;
int i; // esi
char ig; // cl
for (i = 0; i < 40; i++) {
ig = plr[myplr].InvGrid[i];
if (ig > 0 && plr[myplr].InvList[ig - 1]._itype == ITYPE_GOLD)
RemoveInvItem(myplr, ig - 1);
}
for (i = 0; i < MAXBELTITEMS; i++) {
if (plr[myplr].SpdList[i]._itype == ITYPE_GOLD)
plr[myplr].SpdList[i]._itype = -1;
}
plr[myplr]._pGold = 0;
}
void __cdecl MaxSpellsCheat()
{
for(int i = 1; i < MAX_SPELLS; i++) {
if ( spelldata[i].sBookLvl != -1 ) {
plr[myplr]._pMemSpells |= (__int64)1 << (i - 1);
plr[myplr]._pSplLvl[i] = 10;
}
}
for (int i = 1; i < MAX_SPELLS; i++) {
if (spelldata[i].sBookLvl != -1) {
plr[myplr]._pMemSpells |= (__int64)1 << (i - 1);
plr[myplr]._pSplLvl[i] = 10;
}
}
}
void __fastcall SetSpellLevelCheat(char spl, int spllvl)
{
plr[myplr]._pMemSpells |= (__int64)1 << (spl - 1);
plr[myplr]._pSplLvl[spl] = spllvl;
plr[myplr]._pMemSpells |= (__int64)1 << (spl - 1);
plr[myplr]._pSplLvl[spl] = spllvl;
}
void __cdecl SetAllSpellsCheat()
{
SetSpellLevelCheat(SPL_FIREBOLT, 8);
SetSpellLevelCheat(SPL_CBOLT, 11);
SetSpellLevelCheat(SPL_HBOLT, 10);
SetSpellLevelCheat(SPL_HEAL, 7);
SetSpellLevelCheat(SPL_HEALOTHER, 5);
SetSpellLevelCheat(SPL_LIGHTNING, 9);
SetSpellLevelCheat(SPL_FIREWALL, 5);
SetSpellLevelCheat(SPL_TELEKINESIS, 3);
SetSpellLevelCheat(SPL_TOWN, 3);
SetSpellLevelCheat(SPL_FLASH, 3);
SetSpellLevelCheat(SPL_RNDTELEPORT, 2);
SetSpellLevelCheat(SPL_MANASHIELD, 2);
SetSpellLevelCheat(SPL_WAVE, 4);
SetSpellLevelCheat(SPL_FIREBALL, 3);
SetSpellLevelCheat(SPL_STONE, 1);
SetSpellLevelCheat(SPL_CHAIN, 1);
SetSpellLevelCheat(SPL_GUARDIAN, 4);
SetSpellLevelCheat(SPL_ELEMENT, 3);
SetSpellLevelCheat(SPL_NOVA, 1);
SetSpellLevelCheat(SPL_GOLEM, 2);
SetSpellLevelCheat(SPL_FLARE, 1);
SetSpellLevelCheat(SPL_BONESPIRIT, 1);
SetSpellLevelCheat(SPL_FIREBOLT, 8);
SetSpellLevelCheat(SPL_CBOLT, 11);
SetSpellLevelCheat(SPL_HBOLT, 10);
SetSpellLevelCheat(SPL_HEAL, 7);
SetSpellLevelCheat(SPL_HEALOTHER, 5);
SetSpellLevelCheat(SPL_LIGHTNING, 9);
SetSpellLevelCheat(SPL_FIREWALL, 5);
SetSpellLevelCheat(SPL_TELEKINESIS, 3);
SetSpellLevelCheat(SPL_TOWN, 3);
SetSpellLevelCheat(SPL_FLASH, 3);
SetSpellLevelCheat(SPL_RNDTELEPORT, 2);
SetSpellLevelCheat(SPL_MANASHIELD, 2);
SetSpellLevelCheat(SPL_WAVE, 4);
SetSpellLevelCheat(SPL_FIREBALL, 3);
SetSpellLevelCheat(SPL_STONE, 1);
SetSpellLevelCheat(SPL_CHAIN, 1);
SetSpellLevelCheat(SPL_GUARDIAN, 4);
SetSpellLevelCheat(SPL_ELEMENT, 3);
SetSpellLevelCheat(SPL_NOVA, 1);
SetSpellLevelCheat(SPL_GOLEM, 2);
SetSpellLevelCheat(SPL_FLARE, 1);
SetSpellLevelCheat(SPL_BONESPIRIT, 1);
}
void __fastcall PrintDebugPlayer(bool bNextPlayer)
{
char dstr[128]; // [esp+Ch] [ebp-80h]
if ( bNextPlayer )
dbgplr = ((_BYTE)dbgplr + 1) & 3;
sprintf(dstr, "Plr %i : Active = %i", dbgplr, plr[dbgplr].plractive);
NetSendCmdString(1 << myplr, dstr);
if ( plr[dbgplr].plractive )
{
sprintf(dstr, " Plr %i is %s", dbgplr, plr[dbgplr]._pName);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, " Lvl = %i : Change = %i", plr[dbgplr].plrlevel, plr[dbgplr]._pLvlChanging);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, " x = %i, y = %i : tx = %i, ty = %i", plr[dbgplr].WorldX, plr[dbgplr].WorldY, plr[dbgplr]._ptargx, plr[dbgplr]._ptargy);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, " mode = %i : daction = %i : walk[0] = %i", plr[dbgplr]._pmode, plr[dbgplr].destAction, plr[dbgplr].walkpath[0]);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, " inv = %i : hp = %i", plr[dbgplr]._pInvincible, plr[dbgplr]._pHitPoints);
NetSendCmdString(1 << myplr, dstr);
}
char dstr[128]; // [esp+Ch] [ebp-80h]
if (bNextPlayer)
dbgplr = ((_BYTE)dbgplr + 1) & 3;
sprintf(dstr, "Plr %i : Active = %i", dbgplr, plr[dbgplr].plractive);
NetSendCmdString(1 << myplr, dstr);
if (plr[dbgplr].plractive) {
sprintf(dstr, " Plr %i is %s", dbgplr, plr[dbgplr]._pName);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, " Lvl = %i : Change = %i", plr[dbgplr].plrlevel, plr[dbgplr]._pLvlChanging);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, " x = %i, y = %i : tx = %i, ty = %i", plr[dbgplr].WorldX, plr[dbgplr].WorldY, plr[dbgplr]._ptargx, plr[dbgplr]._ptargy);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, " mode = %i : daction = %i : walk[0] = %i", plr[dbgplr]._pmode, plr[dbgplr].destAction, plr[dbgplr].walkpath[0]);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, " inv = %i : hp = %i", plr[dbgplr]._pInvincible, plr[dbgplr]._pHitPoints);
NetSendCmdString(1 << myplr, dstr);
}
}
void __cdecl PrintDebugQuest()
{
char dstr[128]; // [esp+0h] [ebp-80h]
char dstr[128]; // [esp+0h] [ebp-80h]
sprintf(dstr, "Quest %i : Active = %i, Var1 = %i", dbgqst, quests[dbgqst]._qactive, quests[dbgqst]._qvar1);
NetSendCmdString(1 << myplr, dstr);
if ( ++dbgqst == MAXQUESTS )
dbgqst = 0;
sprintf(dstr, "Quest %i : Active = %i, Var1 = %i", dbgqst, quests[dbgqst]._qactive, quests[dbgqst]._qvar1);
NetSendCmdString(1 << myplr, dstr);
if (++dbgqst == MAXQUESTS)
dbgqst = 0;
}
void __fastcall PrintDebugMonster(int m)
{
bool bActive; // ecx
int i; // eax
char dstr[128]; // [esp+Ch] [ebp-80h]
sprintf(dstr, "Monster %i = %s", m, monster[m].mName);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, "X = %i, Y = %i", monster[m]._mx, monster[m]._my);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, "Enemy = %i, HP = %i", monster[m]._menemy, monster[m]._mhitpoints);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, "Mode = %i, Var1 = %i", monster[m]._mmode, monster[m]._mVar1);
NetSendCmdString(1 << myplr, dstr);
bActive = 0;
for(i = 0; i < nummonsters; i++)
{
if ( monstactive[i] == m )
bActive = 1;
}
sprintf(dstr, "Active List = %i, Squelch = %i", bActive, monster[m]._msquelch);
NetSendCmdString(1 << myplr, dstr);
bool bActive; // ecx
int i; // eax
char dstr[128]; // [esp+Ch] [ebp-80h]
sprintf(dstr, "Monster %i = %s", m, monster[m].mName);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, "X = %i, Y = %i", monster[m]._mx, monster[m]._my);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, "Enemy = %i, HP = %i", monster[m]._menemy, monster[m]._mhitpoints);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, "Mode = %i, Var1 = %i", monster[m]._mmode, monster[m]._mVar1);
NetSendCmdString(1 << myplr, dstr);
bActive = 0;
for (i = 0; i < nummonsters; i++) {
if (monstactive[i] == m)
bActive = 1;
}
sprintf(dstr, "Active List = %i, Squelch = %i", bActive, monster[m]._msquelch);
NetSendCmdString(1 << myplr, dstr);
}
void __cdecl GetDebugMonster()
{
int v0; // ecx
int v1; // eax
v0 = pcursmonst;
if ( pcursmonst == -1 )
{
v1 = dMonster[cursmx][cursmy];
if ( v1 )
{
v0 = v1 - 1;
if ( v1 <= 0 )
v0 = -1 - v1;
}
else
{
v0 = dbgmon;
}
}
PrintDebugMonster(v0);
int v0; // ecx
int v1; // eax
v0 = pcursmonst;
if (pcursmonst == -1) {
v1 = dMonster[cursmx][cursmy];
if (v1) {
v0 = v1 - 1;
if (v1 <= 0)
v0 = -1 - v1;
} else {
v0 = dbgmon;
}
}
PrintDebugMonster(v0);
}
void __cdecl NextDebugMonster()
{
char dstr[128]; // [esp+0h] [ebp-80h]
char dstr[128]; // [esp+0h] [ebp-80h]
if ( dbgmon++ == MAXMONSTERS )
dbgmon = 0;
if (dbgmon++ == MAXMONSTERS)
dbgmon = 0;
sprintf(dstr, "Current debug monster = %i", dbgmon);
NetSendCmdString(1 << myplr, dstr);
sprintf(dstr, "Current debug monster = %i", dbgmon);
NetSendCmdString(1 << myplr, dstr);
}
#endif

265
Source/error.cpp

@ -7,118 +7,113 @@ char msgdelay;
char msgflag;
char msgcnt;
char *MsgStrings[44] =
{
"",
"No automap available in town",
"No multiplayer functions in demo",
"Direct Sound Creation Failed",
"Not available in shareware version",
"Not enough space to save",
"No Pause in town",
"Copying to a hard disk is recommended",
"Multiplayer sync problem",
"No pause in multiplayer",
"Loading...",
"Saving...",
"Some are weakened as one grows strong",
"New strength is forged through destruction",
"Those who defend seldom attack",
"The sword of justice is swift and sharp",
"While the spirit is vigilant the body thrives",
"The powers of mana refocused renews",
"Time cannot diminish the power of steel",
"Magic is not always what it seems to be",
"What once was opened now is closed",
"Intensity comes at the cost of wisdom",
"Arcane power brings destruction",
"That which cannot be held cannot be harmed",
"Crimson and Azure become as the sun",
"Knowledge and wisdom at the cost of self",
"Drink and be refreshed",
"Wherever you go, there you are",
"Energy comes at the cost of wisdom",
"Riches abound when least expected",
"Where avarice fails, patience gains reward",
"Blessed by a benevolent companion!",
"The hands of men may be guided by fate",
"Strength is bolstered by heavenly faith",
"The essence of life flows from within",
"The way is made clear when viewed from above",
"Salvation comes at the cost of wisdom",
"Mysteries are revealed in the light of reason",
"Those who are last may yet be first",
"Generosity brings its own rewards",
"You must be at least level 8 to use this.",
"You must be at least level 13 to use this.",
"You must be at least level 17 to use this.",
"Arcane knowledge gained!"
char *MsgStrings[44] = {
"",
"No automap available in town",
"No multiplayer functions in demo",
"Direct Sound Creation Failed",
"Not available in shareware version",
"Not enough space to save",
"No Pause in town",
"Copying to a hard disk is recommended",
"Multiplayer sync problem",
"No pause in multiplayer",
"Loading...",
"Saving...",
"Some are weakened as one grows strong",
"New strength is forged through destruction",
"Those who defend seldom attack",
"The sword of justice is swift and sharp",
"While the spirit is vigilant the body thrives",
"The powers of mana refocused renews",
"Time cannot diminish the power of steel",
"Magic is not always what it seems to be",
"What once was opened now is closed",
"Intensity comes at the cost of wisdom",
"Arcane power brings destruction",
"That which cannot be held cannot be harmed",
"Crimson and Azure become as the sun",
"Knowledge and wisdom at the cost of self",
"Drink and be refreshed",
"Wherever you go, there you are",
"Energy comes at the cost of wisdom",
"Riches abound when least expected",
"Where avarice fails, patience gains reward",
"Blessed by a benevolent companion!",
"The hands of men may be guided by fate",
"Strength is bolstered by heavenly faith",
"The essence of life flows from within",
"The way is made clear when viewed from above",
"Salvation comes at the cost of wisdom",
"Mysteries are revealed in the light of reason",
"Those who are last may yet be first",
"Generosity brings its own rewards",
"You must be at least level 8 to use this.",
"You must be at least level 13 to use this.",
"You must be at least level 17 to use this.",
"Arcane knowledge gained!"
};
void __fastcall InitDiabloMsg(char e)
{
for ( int i = 0; i < msgcnt; i++ ) {
if ( msgtable[i] == e )
return;
}
for (int i = 0; i < msgcnt; i++) {
if (msgtable[i] == e)
return;
}
msgtable[msgcnt] = e;
if ( msgcnt < (BYTE)sizeof(msgtable) )
msgcnt++;
msgtable[msgcnt] = e;
if (msgcnt < (BYTE)sizeof(msgtable))
msgcnt++;
msgflag = msgtable[0];
msgdelay = 70;
msgflag = msgtable[0];
msgdelay = 70;
}
void __cdecl ClrDiabloMsg()
{
for (int i = 0; i < sizeof(msgtable); i++)
msgtable[i] = 0;
for (int i = 0; i < sizeof(msgtable); i++)
msgtable[i] = 0;
msgflag = 0;
msgcnt = 0;
msgflag = 0;
msgcnt = 0;
}
void __cdecl DrawDiabloMsg()
{
int v0; // esi
signed int v1; // edi
int v8; // edi
signed int v9; // ebx
signed int v10; // eax
signed int v11; // ecx
int v12; // esi
signed int v13; // esi
unsigned char v14; // bl
bool v15; // zf
signed int v16; // [esp+Ch] [ebp-8h]
signed int v17; // [esp+Ch] [ebp-8h]
signed int screen_x; // [esp+10h] [ebp-4h]
int v0; // esi
signed int v1; // edi
int v8; // edi
signed int v9; // ebx
signed int v10; // eax
signed int v11; // ecx
int v12; // esi
signed int v13; // esi
unsigned char v14; // bl
bool v15; // zf
signed int v16; // [esp+Ch] [ebp-8h]
signed int v17; // [esp+Ch] [ebp-8h]
signed int screen_x; // [esp+10h] [ebp-4h]
CelDecodeOnly(165, 318, pSTextSlidCels, 1, 12);
CelDecodeOnly(591, 318, pSTextSlidCels, 4, 12);
CelDecodeOnly(165, 366, pSTextSlidCels, 2, 12);
CelDecodeOnly(591, 366, pSTextSlidCels, 3, 12);
screen_x = 173;
v16 = 35;
do
{
CelDecodeOnly(screen_x, 318, pSTextSlidCels, 5, 12);
CelDecodeOnly(screen_x, 366, pSTextSlidCels, 7, 12);
screen_x += 12;
--v16;
}
while ( v16 );
v0 = 330;
v1 = 3;
do
{
CelDecodeOnly(165, v0, pSTextSlidCels, 6, 12);
CelDecodeOnly(591, v0, pSTextSlidCels, 8, 12);
v0 += 12;
--v1;
}
while ( v1 );
CelDecodeOnly(165, 318, pSTextSlidCels, 1, 12);
CelDecodeOnly(591, 318, pSTextSlidCels, 4, 12);
CelDecodeOnly(165, 366, pSTextSlidCels, 2, 12);
CelDecodeOnly(591, 366, pSTextSlidCels, 3, 12);
screen_x = 173;
v16 = 35;
do {
CelDecodeOnly(screen_x, 318, pSTextSlidCels, 5, 12);
CelDecodeOnly(screen_x, 366, pSTextSlidCels, 7, 12);
screen_x += 12;
--v16;
} while (v16);
v0 = 330;
v1 = 3;
do {
CelDecodeOnly(165, v0, pSTextSlidCels, 6, 12);
CelDecodeOnly(591, v0, pSTextSlidCels, 8, 12);
v0 += 12;
--v1;
} while (v1);
#define TRANS_RECT_X 104
#define TRANS_RECT_Y 150
@ -126,46 +121,40 @@ void __cdecl DrawDiabloMsg()
#define TRANS_RECT_HEIGHT 54
#include "asm_trans_rect.inc"
strcpy(tempstr, MsgStrings[msgflag]);
v8 = screen_y_times_768[342] + 165;
v9 = strlen(tempstr);
v10 = 0;
v11 = 0;
v17 = v9;
if ( v9 <= 0 )
goto LABEL_27;
do
{
v12 = (unsigned char)tempstr[v11++];
v10 += fontkern[fontframe[fontidx[v12]]] + 1;
}
while ( v11 < v9 );
if ( v10 < 442 )
LABEL_27:
v8 += (442 - v10) >> 1;
v13 = 0;
if ( v9 > 0 )
{
do
{
v14 = fontframe[fontidx[(unsigned char)tempstr[v13]]];
if ( v14 )
CPrintString(v8, v14, 3);
++v13;
v8 += fontkern[v14] + 1;
}
while ( v13 < v17 );
}
v15 = msgdelay == 0;
if ( msgdelay > 0 )
v15 = --msgdelay == 0;
if ( v15 )
{
v15 = msgcnt-- == 1;
msgdelay = 70;
if ( v15 )
msgflag = 0;
else
msgflag = msgtable[msgcnt];
}
strcpy(tempstr, MsgStrings[msgflag]);
v8 = screen_y_times_768[342] + 165;
v9 = strlen(tempstr);
v10 = 0;
v11 = 0;
v17 = v9;
if (v9 <= 0)
goto LABEL_27;
do {
v12 = (unsigned char)tempstr[v11++];
v10 += fontkern[fontframe[fontidx[v12]]] + 1;
} while (v11 < v9);
if (v10 < 442)
LABEL_27:
v8 += (442 - v10) >> 1;
v13 = 0;
if (v9 > 0) {
do {
v14 = fontframe[fontidx[(unsigned char)tempstr[v13]]];
if (v14)
CPrintString(v8, v14, 3);
++v13;
v8 += fontkern[v14] + 1;
} while (v13 < v17);
}
v15 = msgdelay == 0;
if (msgdelay > 0)
v15 = --msgdelay == 0;
if (v15) {
v15 = msgcnt-- == 1;
msgdelay = 70;
if (v15)
msgflag = 0;
else
msgflag = msgtable[msgcnt];
}
}

4
Source/fault.h

@ -3,8 +3,8 @@
#define __FAULT_H__
struct STACK_FRAME {
STACK_FRAME *pNext;
void *pCallRet;
STACK_FRAME *pNext;
void *pCallRet;
};
//int dword_52B9F4;

339
Source/logging.cpp

@ -6,225 +6,212 @@ int log_cpp_init_value; // weak
static CRITICAL_SECTION sgMemCrit;
CHAR FileName[260]; // idb
char log_buffer[388];
LPCVOID lpAddress; // idb
LPCVOID lpAddress; // idb
DWORD nNumberOfBytesToWrite; // idb
const int log_inf = 0x7F800000; // weak
/* data */
int log_not_created = 1; // weak
int log_not_created = 1; // weak
HANDLE log_file = (HANDLE)0xFFFFFFFF; // idb
struct log_cpp_init_1
{
log_cpp_init_1()
{
log_cpp_init_value = log_inf;
}
struct log_cpp_init_1 {
log_cpp_init_1()
{
log_cpp_init_value = log_inf;
}
} _log_cpp_init_1;
// 47F070: using guessed type int log_inf;
// 646A30: using guessed type int log_cpp_init_value;
struct log_cpp_init_2
{
log_cpp_init_2()
{
log_init_mutex();
j_log_cleanup_mutex();
}
struct log_cpp_init_2 {
log_cpp_init_2()
{
log_init_mutex();
j_log_cleanup_mutex();
}
} _log_cpp_init_2;
void __cdecl log_init_mutex()
{
InitializeCriticalSection(&sgMemCrit);
InitializeCriticalSection(&sgMemCrit);
}
void __cdecl j_log_cleanup_mutex()
{
atexit(log_cleanup_mutex);
atexit(log_cleanup_mutex);
}
void __cdecl log_cleanup_mutex()
{
DeleteCriticalSection(&sgMemCrit);
DeleteCriticalSection(&sgMemCrit);
}
void __cdecl log_flush(bool force_close)
{
void *v1; // eax
DWORD NumberOfBytesWritten; // [esp+8h] [ebp-4h]
EnterCriticalSection(&sgMemCrit);
if ( nNumberOfBytesToWrite )
{
if ( log_file == (HANDLE)-1 )
{
v1 = log_create();
log_file = v1;
if ( v1 == (void *)-1 )
{
nNumberOfBytesToWrite = 0;
return;
}
SetFilePointer(v1, 0, NULL, FILE_END);
}
WriteFile(log_file, lpAddress, nNumberOfBytesToWrite, &NumberOfBytesWritten, 0);
nNumberOfBytesToWrite = 0;
}
if ( force_close && log_file != (HANDLE)-1 )
{
CloseHandle(log_file);
log_file = (HANDLE)-1;
}
LeaveCriticalSection(&sgMemCrit);
void *v1; // eax
DWORD NumberOfBytesWritten; // [esp+8h] [ebp-4h]
EnterCriticalSection(&sgMemCrit);
if (nNumberOfBytesToWrite) {
if (log_file == (HANDLE)-1) {
v1 = log_create();
log_file = v1;
if (v1 == (void *)-1) {
nNumberOfBytesToWrite = 0;
return;
}
SetFilePointer(v1, 0, NULL, FILE_END);
}
WriteFile(log_file, lpAddress, nNumberOfBytesToWrite, &NumberOfBytesWritten, 0);
nNumberOfBytesToWrite = 0;
}
if (force_close && log_file != (HANDLE)-1) {
CloseHandle(log_file);
log_file = (HANDLE)-1;
}
LeaveCriticalSection(&sgMemCrit);
}
void *__cdecl log_create()
{
char *v0; // eax
void *v1; // ebx
HANDLE v2; // eax
char *v3; // edx
char Filename[260]; // [esp+Ch] [ebp-15Ch]
VS_FIXEDFILEINFO file_info; // [esp+110h] [ebp-58h]
char Buffer[32]; // [esp+144h] [ebp-24h]
DWORD pcbBuffer; // [esp+164h] [ebp-4h]
if ( log_not_created )
{
if ( GetModuleFileName(0, Filename, 0x104u) && (v0 = strrchr(Filename, '\\')) != 0 )
v0[1] = 0;
else
Filename[0] = 0;
pcbBuffer = 32;
if ( !GetUserName(Buffer, &pcbBuffer) )
Buffer[0] = 0;
log_get_version(&file_info);
_snprintf(
FileName,
0x104u,
"%s%s%02u%02u%02u.ERR",
Filename,
Buffer,
_LOWORD(file_info.dwProductVersionMS),
file_info.dwProductVersionLS >> 16,
_LOWORD(file_info.dwProductVersionLS));
}
v1 = (void *)-1;
for ( pcbBuffer = log_not_created == 0; (signed int)pcbBuffer < 2; ++pcbBuffer )
{
v2 = CreateFile(FileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
v1 = v2;
if ( v2 != (HANDLE)-1 )
{
if ( GetFileSize(v2, 0) > 0x10000 )
SetEndOfFile(v1);
break;
}
v3 = strrchr(FileName, '\\');
if ( !v3 )
v3 = FileName;
strcpy(Filename, "c:\\");
memset(&Filename[4], 0, 0x100u);
strcat(Filename, v3);
strcpy(FileName, Filename);
}
log_not_created = 0;
return v1;
char *v0; // eax
void *v1; // ebx
HANDLE v2; // eax
char *v3; // edx
char Filename[260]; // [esp+Ch] [ebp-15Ch]
VS_FIXEDFILEINFO file_info; // [esp+110h] [ebp-58h]
char Buffer[32]; // [esp+144h] [ebp-24h]
DWORD pcbBuffer; // [esp+164h] [ebp-4h]
if (log_not_created) {
if (GetModuleFileName(0, Filename, 0x104u) && (v0 = strrchr(Filename, '\\')) != 0)
v0[1] = 0;
else
Filename[0] = 0;
pcbBuffer = 32;
if (!GetUserName(Buffer, &pcbBuffer))
Buffer[0] = 0;
log_get_version(&file_info);
_snprintf(
FileName,
0x104u,
"%s%s%02u%02u%02u.ERR",
Filename,
Buffer,
_LOWORD(file_info.dwProductVersionMS),
file_info.dwProductVersionLS >> 16,
_LOWORD(file_info.dwProductVersionLS));
}
v1 = (void *)-1;
for (pcbBuffer = log_not_created == 0; (signed int)pcbBuffer < 2; ++pcbBuffer) {
v2 = CreateFile(FileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
v1 = v2;
if (v2 != (HANDLE)-1) {
if (GetFileSize(v2, 0) > 0x10000)
SetEndOfFile(v1);
break;
}
v3 = strrchr(FileName, '\\');
if (!v3)
v3 = FileName;
strcpy(Filename, "c:\\");
memset(&Filename[4], 0, 0x100u);
strcat(Filename, v3);
strcpy(FileName, Filename);
}
log_not_created = 0;
return v1;
}
// 4947D4: using guessed type int log_not_created;
void __fastcall log_get_version(VS_FIXEDFILEINFO *file_info)
{
DWORD v1; // eax
DWORD v2; // esi
void *v3; // ebx
unsigned int v4; // eax
char Filename[260]; // [esp+8h] [ebp-114h]
DWORD dwHandle; // [esp+10Ch] [ebp-10h]
LPVOID lpBuffer; // [esp+110h] [ebp-Ch]
unsigned int puLen; // [esp+114h] [ebp-8h]
void *v9; // [esp+118h] [ebp-4h]
v9 = file_info;
memset(file_info, 0, 0x34u);
if ( GetModuleFileName(0, Filename, 0x104u) )
{
v1 = GetFileVersionInfoSize(Filename, &dwHandle);
v2 = v1;
if ( v1 )
{
v3 = VirtualAlloc(0, v1, 0x1000u, 4u);
if ( GetFileVersionInfo(Filename, 0, v2, v3) && VerQueryValue(v3, "\\", &lpBuffer, &puLen) )
{
v4 = puLen;
if ( puLen >= 0x34 )
v4 = 52;
memcpy(v9, lpBuffer, v4);
}
VirtualFree(v3, 0, 0x8000u);
}
}
DWORD v1; // eax
DWORD v2; // esi
void *v3; // ebx
unsigned int v4; // eax
char Filename[260]; // [esp+8h] [ebp-114h]
DWORD dwHandle; // [esp+10Ch] [ebp-10h]
LPVOID lpBuffer; // [esp+110h] [ebp-Ch]
unsigned int puLen; // [esp+114h] [ebp-8h]
void *v9; // [esp+118h] [ebp-4h]
v9 = file_info;
memset(file_info, 0, 0x34u);
if (GetModuleFileName(0, Filename, 0x104u)) {
v1 = GetFileVersionInfoSize(Filename, &dwHandle);
v2 = v1;
if (v1) {
v3 = VirtualAlloc(0, v1, 0x1000u, 4u);
if (GetFileVersionInfo(Filename, 0, v2, v3) && VerQueryValue(v3, "\\", &lpBuffer, &puLen)) {
v4 = puLen;
if (puLen >= 0x34)
v4 = 52;
memcpy(v9, lpBuffer, v4);
}
VirtualFree(v3, 0, 0x8000u);
}
}
}
void log_printf(const char *pszFmt, ...)
{
size_t v1; // edi
char *v2; // eax
char v3[512]; // [esp+Ch] [ebp-200h]
va_list va; // [esp+218h] [ebp+Ch]
va_start(va, pszFmt);
EnterCriticalSection(&sgMemCrit);
_vsnprintf(v3, 0x200u, pszFmt, va);
va_end(va);
v3[511] = 0;
v1 = strlen(v3);
if ( v1 + nNumberOfBytesToWrite > 0x1000 )
log_flush(0);
v2 = (char *)lpAddress;
if ( lpAddress
|| (v2 = (char *)VirtualAlloc((LPVOID)lpAddress, 0x1000u, 0x1000u, 4u),
nNumberOfBytesToWrite = 0,
(lpAddress = v2) != 0) )
{
memcpy(&v2[nNumberOfBytesToWrite], v3, v1);
nNumberOfBytesToWrite += v1;
}
LeaveCriticalSection(&sgMemCrit);
size_t v1; // edi
char *v2; // eax
char v3[512]; // [esp+Ch] [ebp-200h]
va_list va; // [esp+218h] [ebp+Ch]
va_start(va, pszFmt);
EnterCriticalSection(&sgMemCrit);
_vsnprintf(v3, 0x200u, pszFmt, va);
va_end(va);
v3[511] = 0;
v1 = strlen(v3);
if (v1 + nNumberOfBytesToWrite > 0x1000)
log_flush(0);
v2 = (char *)lpAddress;
if (lpAddress
|| (v2 = (char *)VirtualAlloc((LPVOID)lpAddress, 0x1000u, 0x1000u, 4u),
nNumberOfBytesToWrite = 0,
(lpAddress = v2) != 0)) {
memcpy(&v2[nNumberOfBytesToWrite], v3, v1);
nNumberOfBytesToWrite += v1;
}
LeaveCriticalSection(&sgMemCrit);
}
void __cdecl log_dump_computer_info()
{
char Buffer[64]; // [esp+0h] [ebp-88h]
VS_FIXEDFILEINFO file_info; // [esp+40h] [ebp-48h]
struct _SYSTEMTIME SystemTime; // [esp+74h] [ebp-14h]
DWORD pcbBuffer; // [esp+84h] [ebp-4h]
GetLocalTime(&SystemTime);
pcbBuffer = 64;
if ( !GetUserName(Buffer, &pcbBuffer) )
Buffer[0] = 0;
log_get_version(&file_info);
log_printf(
"\r\n"
"------------------------------------------------------\r\n"
"PROGRAM VERSION: %d.%d.%d.%d\r\n"
"COMPUTER NAME: %s\r\n"
"TIME: %02u/%02u/%02u %02u:%02u:%02u\r\n"
"INFO: %s\r\n"
"\r\n",
file_info.dwProductVersionMS >> 16,
_LOWORD(file_info.dwProductVersionMS),
file_info.dwProductVersionLS >> 16,
_LOWORD(file_info.dwProductVersionLS),
Buffer,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wYear % 100,
SystemTime.wHour,
SystemTime.wMinute,
SystemTime.wSecond,
log_buffer);
char Buffer[64]; // [esp+0h] [ebp-88h]
VS_FIXEDFILEINFO file_info; // [esp+40h] [ebp-48h]
struct _SYSTEMTIME SystemTime; // [esp+74h] [ebp-14h]
DWORD pcbBuffer; // [esp+84h] [ebp-4h]
GetLocalTime(&SystemTime);
pcbBuffer = 64;
if (!GetUserName(Buffer, &pcbBuffer))
Buffer[0] = 0;
log_get_version(&file_info);
log_printf(
"\r\n"
"------------------------------------------------------\r\n"
"PROGRAM VERSION: %d.%d.%d.%d\r\n"
"COMPUTER NAME: %s\r\n"
"TIME: %02u/%02u/%02u %02u:%02u:%02u\r\n"
"INFO: %s\r\n"
"\r\n",
file_info.dwProductVersionMS >> 16,
_LOWORD(file_info.dwProductVersionMS),
file_info.dwProductVersionLS >> 16,
_LOWORD(file_info.dwProductVersionLS),
Buffer,
SystemTime.wMonth,
SystemTime.wDay,
SystemTime.wYear % 100,
SystemTime.wHour,
SystemTime.wMinute,
SystemTime.wSecond,
log_buffer);
}

6
Source/logging.h

@ -3,9 +3,9 @@
#define __LOGGING_H__
extern int log_cpp_init_value; // weak
extern CHAR FileName[260]; // idb
extern CHAR FileName[260]; // idb
extern char log_buffer[388];
extern LPCVOID lpAddress; // idb
extern LPCVOID lpAddress; // idb
extern DWORD nNumberOfBytesToWrite; // idb
void __cdecl log_cpp_init_1();
@ -26,6 +26,6 @@ extern const int log_inf; // weak
/* data */
extern int log_not_created; // weak
extern HANDLE log_file; // idb
extern HANDLE log_file; // idb
#endif /* __LOGGING_H__ */

2
types.h

@ -40,9 +40,9 @@
#include "enums.h"
#include "structs.h"
#include "3rdParty/PKWare/pkware.h"
#include "3rdParty/Storm/Source/storm.h"
#include "DiabloUI/diabloui.h"
#include "3rdParty/PKWare/pkware.h"
// If defined, use copy protection [Default -> Defined]
//#define COPYPROT

Loading…
Cancel
Save