diff --git a/Source/effects.cpp b/Source/effects.cpp index 06fd2541a..0da261966 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -2,13 +2,12 @@ #include "../types.h" -int effects_cpp_init_value; // weak -int sfxdelay; // weak +static float effects_cpp_init_value = INFINITY; +int sfxdelay; // weak int sfxdnum; void *sfx_stream; TSFX *sfx_data_cur; -const int effects_inf = 0x7F800000; // weak const char monster_action_sounds[] = { 'a', 'h', 'd', 's' }; // idb /* data */ @@ -877,15 +876,6 @@ TSFX sgSFX[NUM_SFX] = { // clang-format on }; -struct effects_cpp_init { - effects_cpp_init() - { - effects_cpp_init_value = effects_inf; - } -} _effects_cpp_init; -// 47A468: using guessed type int effects_inf; -// 52A550: using guessed type int effects_cpp_init_value; - BOOL __fastcall effect_is_playing(int nSFX) { TSFX *sfx = &sgSFX[nSFX]; @@ -913,15 +903,16 @@ void __fastcall InitMonsterSND(int monst) TSnd *pSnd; char name[MAX_PATH]; char *path; + int mtype, i, j; if (!gbSndInited) { return; } - int mtype = Monsters[monst].mtype; - for (int i = 0; i < 4; i++) { + mtype = Monsters[monst].mtype; + for (i = 0; i < 4; i++) { if (monster_action_sounds[i] != 's' || monsterdata[mtype].snd_special) { - for (int j = 0; j < 2; j++) { + for (j = 0; j < 2; j++) { sprintf(name, monsterdata[mtype].sndfile, monster_action_sounds[i], j + 1); path = (char *)DiabloAllocPtr(strlen(name) + 1); strcpy(path, name); @@ -936,14 +927,18 @@ void __fastcall InitMonsterSND(int monst) void __cdecl FreeEffects() { - for (int i = 0; i < nummtypes; i++) { - int mtype = Monsters[i].mtype; - for (int j = 0; j < 4; ++j) { - for (int k = 0; k < 2; ++k) { - TSnd *pSnd = Monsters[i].Snds[j][k]; + int mtype, i, j, k; + char *file; + TSnd *pSnd; + + for (i = 0; i < nummtypes; i++) { + mtype = Monsters[i].mtype; + for (j = 0; j < 4; ++j) { + for (k = 0; k < 2; ++k) { + pSnd = Monsters[i].Snds[j][k]; if (pSnd) { Monsters[i].Snds[j][k] = NULL; - char *file = pSnd->sound_path; + file = pSnd->sound_path; pSnd->sound_path = NULL; sound_file_cleanup(pSnd); mem_free_dbg(file); @@ -955,22 +950,24 @@ void __cdecl FreeEffects() void __fastcall PlayEffect(int i, int mode) { + int sndIdx, mi, lVolume, lPan; + TSnd *snd; + if (plr[myplr].pLvlLoad) { return; } - int sndIdx = random(164, 2); + sndIdx = random(164, 2); if (!gbSndInited || !gbSoundOn || gbBufferMsgs) { return; } - int mi = monster[i]._mMTidx; - TSnd *snd = Monsters[mi].Snds[mode][sndIdx]; + mi = monster[i]._mMTidx; + snd = Monsters[mi].Snds[mode][sndIdx]; if (!snd || snd_playing(snd)) { return; } - int lVolume, lPan; if (!calc_snd_position(monster[i]._mx, monster[i]._my, &lVolume, &lPan)) return; @@ -980,16 +977,18 @@ void __fastcall PlayEffect(int i, int mode) BOOL __fastcall calc_snd_position(int x, int y, int *plVolume, int *plPan) { + int pan, volume; + x -= plr[myplr].WorldX; y -= plr[myplr].WorldY; - int pan = (x - y) << 8; + pan = (x - y) << 8; *plPan = pan; if (abs(pan) > 6400) return FALSE; - int volume = abs(x) > abs(y) ? abs(x) : abs(y); + volume = abs(x) > abs(y) ? abs(x) : abs(y); volume <<= 6; *plVolume = volume; @@ -1009,6 +1008,8 @@ void __fastcall PlaySFX(int psfx) void __fastcall PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y) { + int lPan, lVolume; + if (plr[myplr].pLvlLoad && gbMaxPlayers != 1) { return; } @@ -1020,8 +1021,8 @@ void __fastcall PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y) return; } - int lPan = 0; - int lVolume = 0; + lPan = 0; + lVolume = 0; if (loc && !calc_snd_position(x, y, &lVolume, &lPan)) { return; } @@ -1042,6 +1043,8 @@ void __fastcall PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y) void __fastcall stream_play(TSFX *pSFX, int lVolume, int lPan) { + BOOL success; + /// ASSERT: assert(pSFX); /// ASSERT: assert(pSFX->bFlags & sfx_STREAM); sfx_stop(); @@ -1052,7 +1055,7 @@ void __fastcall stream_play(TSFX *pSFX, int lVolume, int lPan) #ifdef _DEBUG SFileEnableDirectAccess(FALSE); #endif - BOOL success = SFileOpenFile(pSFX->pszName, &sfx_stream); + success = SFileOpenFile(pSFX->pszName, &sfx_stream); #ifdef _DEBUG SFileEnableDirectAccess(TRUE); #endif @@ -1101,10 +1104,12 @@ int __fastcall RndSFX(int psfx) void __fastcall PlaySfxLoc(int psfx, int x, int y) { + TSnd *pSnd; + psfx = RndSFX(psfx); if (psfx >= 0 && psfx <= 3) { - TSnd *pSnd = sgSFX[psfx].pSnd; + pSnd = sgSFX[psfx].pSnd; if (pSnd) pSnd->start_tc = 0; } @@ -1114,13 +1119,15 @@ void __fastcall PlaySfxLoc(int psfx, int x, int y) void __cdecl FreeMonsterSnd() { + int i, j, k; + snd_update(TRUE); sfx_stop(); sound_stop(); - for (int i = 0; i < nummtypes; i++) { - for (int j = 0; j < 4; j++) { - for (int k = 0; k < 2; k++) { + for (i = 0; i < nummtypes; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 2; k++) { snd_stop_snd(Monsters[i].Snds[j][k]); } } @@ -1164,9 +1171,11 @@ void __cdecl sound_update() void __cdecl effects_cleanup_sfx() { + DWORD i; + FreeMonsterSnd(); - for (DWORD i = 0; i < NUM_SFX; i++) { + for (i = 0; i < NUM_SFX; i++) { if (sgSFX[i].pSnd) { sound_file_cleanup(sgSFX[i].pSnd); sgSFX[i].pSnd = NULL; @@ -1195,19 +1204,22 @@ void __cdecl stream_update() void __fastcall priv_sound_init(UCHAR bLoadMask) { + UCHAR pc, bFlags; + DWORD i; + if (!gbSndInited) { return; } - UCHAR pc = bLoadMask & (SFX_ROGUE | SFX_WARRIOR | SFX_SORCEROR); + pc = bLoadMask & (SFX_ROGUE | SFX_WARRIOR | SFX_SORCEROR); bLoadMask ^= pc; - for (DWORD i = 0; i < NUM_SFX; i++) { + for (i = 0; i < NUM_SFX; i++) { if (sgSFX[i].pSnd) { continue; } - UCHAR bFlags = sgSFX[i].bFlags; + bFlags = sgSFX[i].bFlags; if (bFlags & SFX_STREAM) { continue; } @@ -1231,11 +1243,13 @@ void __cdecl sound_init() void __stdcall effects_play_sound(char *snd_file) { + DWORD i; + if (!gbSndInited || !gbSoundOn) { return; } - for (DWORD i = 0; i < NUM_SFX; i++) { + for (i = 0; i < NUM_SFX; i++) { if (!_strcmpi(sgSFX[i].pszName, snd_file) && sgSFX[i].pSnd) { if (!snd_playing(sgSFX[i].pSnd)) snd_play_snd(sgSFX[i].pSnd, 0, 0); diff --git a/Source/effects.h b/Source/effects.h index 31c037790..f52d840fb 100644 --- a/Source/effects.h +++ b/Source/effects.h @@ -2,8 +2,7 @@ #ifndef __EFFECTS_H__ #define __EFFECTS_H__ -extern int effects_cpp_init_value; // weak -extern int sfxdelay; // weak +extern int sfxdelay; // weak extern int sfxdnum; extern void *sfx_stream; extern TSFX *sfx_data_cur; diff --git a/Source/encrypt.cpp b/Source/encrypt.cpp index 83d8ec82e..f24f434ea 100644 --- a/Source/encrypt.cpp +++ b/Source/encrypt.cpp @@ -6,9 +6,12 @@ DWORD hashtable[1280]; void __fastcall Decrypt(void *block, DWORD size, DWORD key) { - DWORD *castBlock = (DWORD *)block; - DWORD seed = 0xEEEEEEEE; - for (DWORD i = 0; i < (size >> 2); i++) { + DWORD *castBlock; + DWORD seed, i; + + castBlock = (DWORD *)block; + seed = 0xEEEEEEEE; + for (i = 0; i < (size >> 2); i++) { seed += hashtable[0x400 + (key & 0xFF)]; *castBlock ^= seed + key; seed += *castBlock + (seed << 5) + 3; @@ -19,10 +22,13 @@ void __fastcall Decrypt(void *block, DWORD size, DWORD key) void __fastcall Encrypt(void *block, DWORD size, DWORD key) { - DWORD *castBlock = (DWORD *)block; - DWORD seed = 0xEEEEEEEE; - for (DWORD i = 0; i < (size >> 2); i++) { - DWORD ch = *castBlock; + DWORD *castBlock; + DWORD seed, i, ch; + + castBlock = (DWORD *)block; + seed = 0xEEEEEEEE; + for (i = 0; i < (size >> 2); i++) { + ch = *castBlock; seed += hashtable[0x400 + (key & 0xFF)]; *castBlock ^= seed + key; seed += ch + (seed << 5) + 3; @@ -34,8 +40,10 @@ void __fastcall Encrypt(void *block, DWORD size, DWORD key) DWORD __fastcall Hash(const char *s, int type) { char ch; - DWORD seed1 = 0x7FED7FED; - DWORD seed2 = 0xEEEEEEEE; + DWORD seed1, seed2; + + seed1 = 0x7FED7FED; + seed2 = 0xEEEEEEEE; while (s != NULL && *s) { ch = *s++; ch = toupper(ch); @@ -47,12 +55,15 @@ DWORD __fastcall Hash(const char *s, int type) void __cdecl InitHash() { - DWORD seed = 0x00100001; + DWORD seed, ch; + int i, j; + + seed = 0x00100001; - for (int i = 0; i < 256; i++) { - for (int j = 0; j < 5; j++) { + for ( i = 0; i < 256; i++) { + for ( j = 0; j < 5; j++) { seed = (125 * seed + 3) % 0x2AAAAB; - DWORD ch = (seed & 0xFFFF); + ch = (seed & 0xFFFF); seed = (125 * seed + 3) % 0x2AAAAB; hashtable[i + j * 256] = ch << 16 | (seed & 0xFFFF); } @@ -61,24 +72,28 @@ void __cdecl InitHash() int __fastcall PkwareCompress(void *buf, int size) { - BYTE *srcData = (BYTE *)buf; - char *ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE); + BYTE *srcData, *destData; + char *ptr; + unsigned int destSize, type, dsize; + TDataInfo param; + + srcData = (BYTE *)buf; + ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE); - unsigned int destSize = 2 * size; + destSize = 2 * size; if (destSize < 8192) destSize = 8192; - BYTE *destData = (BYTE *)DiabloAllocPtr(destSize); + destData = (BYTE *)DiabloAllocPtr(destSize); - TDataInfo param; param.srcData = srcData; param.srcOffset = 0; param.destData = destData; param.destOffset = 0; param.size = size; - unsigned int type = 0; - unsigned int dsize = 4096; + type = 0; + dsize = 4096; implode(PkwareBufferRead, PkwareBufferWrite, ptr, ¶m, &type, &dsize); if (param.destOffset < size) { @@ -94,9 +109,11 @@ int __fastcall PkwareCompress(void *buf, int size) unsigned int __cdecl PkwareBufferRead(char *buf, unsigned int *size, void *param) { - TDataInfo *pInfo = (TDataInfo *)param; - + TDataInfo *pInfo; DWORD sSize; + + pInfo = (TDataInfo *)param; + if (*size >= pInfo->size - pInfo->srcOffset) { sSize = pInfo->size - pInfo->srcOffset; } else { @@ -111,7 +128,9 @@ unsigned int __cdecl PkwareBufferRead(char *buf, unsigned int *size, void *param void __cdecl PkwareBufferWrite(char *buf, unsigned int *size, void *param) { - TDataInfo *pInfo = (TDataInfo *)param; + TDataInfo *pInfo; + + pInfo = (TDataInfo *)param; memcpy(pInfo->destData + pInfo->destOffset, buf, *size); pInfo->destOffset += *size; @@ -119,11 +138,14 @@ void __cdecl PkwareBufferWrite(char *buf, unsigned int *size, void *param) void __fastcall PkwareDecompress(void *param, int recv_size, int dwMaxBytes) { - char *ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE); - BYTE *pbInBuff = (BYTE *)param; - BYTE *pbOutBuff = DiabloAllocPtr(dwMaxBytes); - + char *ptr; + BYTE *pbInBuff, *pbOutBuff; TDataInfo info; + + ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE); + pbInBuff = (BYTE *)param; + pbOutBuff = DiabloAllocPtr(dwMaxBytes); + info.srcData = pbInBuff; info.srcOffset = 0; info.destData = pbOutBuff; diff --git a/Source/engine.cpp b/Source/engine.cpp index b68de615a..83fef3a9b 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -2,7 +2,7 @@ #include "../types.h" -int engine_cpp_init_value; // weak +static float engine_cpp_init_value = INFINITY; char gbPixelCol; // automap pixel color 8-bit (palette entry) int dword_52B970; // BOOLEAN flip - if y < x int orgseed; // weak @@ -12,19 +12,9 @@ static CRITICAL_SECTION sgMemCrit; int SeedCount; // weak int dword_52B99C; // BOOLEAN valid - if x/y are in bounds -const int engine_inf = 0x7F800000; // weak const int rand_increment = 1; // unused const int rand_multiplier = 0x015A4E35; // unused -struct engine_cpp_init_1 { - engine_cpp_init_1() - { - engine_cpp_init_value = engine_inf; - } -} _engine_cpp_init_1; -// 47A474: using guessed type int engine_inf; -// 52B968: using guessed type int engine_cpp_init_value; - void __fastcall CelDrawDatOnly(char *pDecodeTo, char *pRLEBytes, int dwRLESize, int dwRLEWdt) { char *v4; // esi diff --git a/Source/engine.h b/Source/engine.h index 124ca4a61..659e81e89 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -5,7 +5,6 @@ //offset 0 //pCelBuff->pFrameTable[0] -extern int engine_cpp_init_value; // weak extern char gbPixelCol; // automap pixel color 8-bit (palette entry) extern int dword_52B970; // bool flip - if y < x extern int orgseed; // weak diff --git a/Source/error.cpp b/Source/error.cpp index 6e20a6acc..81998bd59 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -56,7 +56,9 @@ char *MsgStrings[44] = { void __fastcall InitDiabloMsg(char e) { - for (int i = 0; i < msgcnt; i++) { + int i; + + for (i = 0; i < msgcnt; i++) { if (msgtable[i] == e) return; } @@ -71,7 +73,9 @@ void __fastcall InitDiabloMsg(char e) void __cdecl ClrDiabloMsg() { - for (int i = 0; i < sizeof(msgtable); i++) + int i; + + for (i = 0; i < sizeof(msgtable); i++) msgtable[i] = 0; msgflag = 0; diff --git a/Source/fault.cpp b/Source/fault.cpp index e161549c8..c0ff74fd9 100644 --- a/Source/fault.cpp +++ b/Source/fault.cpp @@ -29,19 +29,22 @@ void __cdecl exception_init_filter() LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) { - log_dump_computer_info(); - PEXCEPTION_RECORD xcpt = ExceptionInfo->ExceptionRecord; - + PEXCEPTION_RECORD xcpt; char szExceptionNameBuf[MAX_PATH]; - char *pszExceptionName = exception_get_error_type(ExceptionInfo->ExceptionRecord->ExceptionCode, szExceptionNameBuf, sizeof(szExceptionNameBuf)); - log_printf("Exception code: %08X %s\r\n", xcpt->ExceptionCode, pszExceptionName); - char szModuleName[MAX_PATH]; + char *pszExceptionName; int sectionNumber, sectionOffset; + PCONTEXT ctx; + + log_dump_computer_info(); + xcpt = ExceptionInfo->ExceptionRecord; + pszExceptionName = exception_get_error_type(ExceptionInfo->ExceptionRecord->ExceptionCode, szExceptionNameBuf, sizeof(szExceptionNameBuf)); + log_printf("Exception code: %08X %s\r\n", xcpt->ExceptionCode, pszExceptionName); + exception_unknown_module(xcpt->ExceptionAddress, szModuleName, MAX_PATH, §ionNumber, §ionOffset); log_printf("Fault address:\t%08X %02X:%08X %s\r\n", xcpt->ExceptionAddress, sectionNumber, sectionOffset, szModuleName); - PCONTEXT ctx = ExceptionInfo->ContextRecord; + ctx = ExceptionInfo->ContextRecord; log_printf("\r\nRegisters:\r\n"); log_printf( @@ -75,10 +78,11 @@ LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) void __fastcall exception_hex_format(BYTE *ptr, unsigned int numBytes) { - DWORD i; + DWORD i, bytesRead; + const char *fmt; + BYTE c; while (numBytes > 0) { - DWORD bytesRead; if (numBytes < 16) bytesRead = numBytes; else @@ -90,7 +94,7 @@ void __fastcall exception_hex_format(BYTE *ptr, unsigned int numBytes) log_printf("0x%08x: ", ptr); for (i = 0; i < 16; ++i) { - const char *fmt = "%02x "; + fmt = "%02x "; if (i >= bytesRead) fmt = " "; log_printf(fmt, ptr[i]); @@ -99,7 +103,6 @@ void __fastcall exception_hex_format(BYTE *ptr, unsigned int numBytes) } for (i = 0; i < bytesRead; i++) { - BYTE c; if (isprint(ptr[i])) c = ptr[i]; else @@ -116,15 +119,22 @@ void __fastcall exception_hex_format(BYTE *ptr, unsigned int numBytes) void __fastcall exception_unknown_module(LPCVOID lpAddress, LPSTR lpModuleName, int iMaxLength, int *sectionNum, int *sectionOffset) { + MEMORY_BASIC_INFORMATION memInfo; + PIMAGE_DOS_HEADER dosHeader; + LONG ntOffset; + PIMAGE_NT_HEADERS ntHeader; + PIMAGE_SECTION_HEADER section; + DWORD numSections, moduleOffset, sectionSize, sectionAddress; + int i; + lstrcpyn(lpModuleName, "*unknown*", iMaxLength); *sectionNum = 0; *sectionOffset = 0; - MEMORY_BASIC_INFORMATION memInfo; if (!VirtualQuery(lpAddress, &memInfo, sizeof(memInfo))) return; - PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)memInfo.AllocationBase; + dosHeader = (PIMAGE_DOS_HEADER)memInfo.AllocationBase; if (!memInfo.AllocationBase) dosHeader = (PIMAGE_DOS_HEADER)GetModuleHandle(0); @@ -134,16 +144,16 @@ void __fastcall exception_unknown_module(LPCVOID lpAddress, LPSTR lpModuleName, } if (dosHeader && dosHeader->e_magic == IMAGE_DOS_SIGNATURE) { - LONG ntOffset = dosHeader->e_lfanew; + ntOffset = dosHeader->e_lfanew; if (ntOffset) { - PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS)((DWORD)dosHeader + ntOffset); + ntHeader = (PIMAGE_NT_HEADERS)((DWORD)dosHeader + ntOffset); if (ntHeader->Signature == IMAGE_NT_SIGNATURE) { - PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(ntHeader); - DWORD numSections = ntHeader->FileHeader.NumberOfSections; - DWORD moduleOffset = (BYTE *)lpAddress - (BYTE *)dosHeader; - for (int i = 0; i < numSections; i++, section++) { - DWORD sectionSize = section->SizeOfRawData; - DWORD sectionAddress = section->VirtualAddress; + section = IMAGE_FIRST_SECTION(ntHeader); + numSections = ntHeader->FileHeader.NumberOfSections; + moduleOffset = (BYTE *)lpAddress - (BYTE *)dosHeader; + for (i = 0; i < numSections; i++, section++) { + sectionSize = section->SizeOfRawData; + sectionAddress = section->VirtualAddress; if (section->SizeOfRawData <= section->Misc.VirtualSize) sectionSize = section->Misc.VirtualSize; @@ -161,11 +171,11 @@ void __fastcall exception_unknown_module(LPCVOID lpAddress, LPSTR lpModuleName, void __fastcall exception_call_stack(void *instr, STACK_FRAME *stackFrame) { STACK_FRAME *oldStackFrame; + char szModuleName[MAX_PATH]; + int sectionNumber, sectionOffset; log_printf("Call stack:\r\nAddress Frame Logical addr Module\r\n"); do { - char szModuleName[MAX_PATH]; - int sectionNumber, sectionOffset; exception_unknown_module(instr, szModuleName, MAX_PATH, §ionNumber, §ionOffset); log_printf("%08X %08X %04X:%08X %s\r\n", instr, stackFrame, sectionNumber, sectionOffset, szModuleName); @@ -190,6 +200,7 @@ void __fastcall exception_call_stack(void *instr, STACK_FRAME *stackFrame) char *__fastcall exception_get_error_type(DWORD dwMessageId, LPSTR lpString1, DWORD nSize) { const char *v4; // eax + HMODULE ntdll; switch (dwMessageId) { CASE_EXCEPTION(v4, STACK_OVERFLOW); @@ -215,7 +226,7 @@ char *__fastcall exception_get_error_type(DWORD dwMessageId, LPSTR lpString1, DW CASE_EXCEPTION(v4, SINGLE_STEP); CASE_EXCEPTION(v4, ACCESS_VIOLATION); default: - HMODULE ntdll = GetModuleHandle("NTDLL.DLL"); + ntdll = GetModuleHandle("NTDLL.DLL"); if (!FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, ntdll, dwMessageId, 0, lpString1, nSize, NULL)) { v4 = "*unknown*"; } diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index 625c8ab15..dae2a442d 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -85,7 +85,9 @@ void __cdecl gamemenu_handle_previous() void __cdecl gamemenu_new_game() { - for (int i = 0; i < MAX_PLRS; i++) { + int i; + + for (i = 0; i < MAX_PLRS; i++) { plr[i]._pmode = PM_QUIT; plr[i]._pInvincible = TRUE; } diff --git a/Source/init.cpp b/Source/init.cpp index 2717de743..05dfff0fd 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -3,7 +3,7 @@ #include "../types.h" _SNETVERSIONDATA fileinfo; -int init_cpp_init_value; // weak +static float init_cpp_init_value = INFINITY; int gbActive; // weak char diablo_exe_path[260]; void *unused_mpq; @@ -15,22 +15,11 @@ void *patch_rt_mpq; int killed_mom_parent; // weak BOOLEAN screensaver_enabled_prev; -const int init_inf = 0x7F800000; // weak - /* data */ char gszVersionNumber[260] = "internal version unknown"; char gszProductName[260] = "Diablo v1.09"; -struct init_cpp_init { - init_cpp_init() - { - init_cpp_init_value = init_inf; - } -} _init_cpp_init; -// 47AE20: using guessed type int init_inf; -// 63497C: using guessed type int init_cpp_init_value; - void __fastcall init_cleanup(BOOLEAN show_cursor) { int v1; // edi diff --git a/Source/init.h b/Source/init.h index 45e641c21..f23cd349e 100644 --- a/Source/init.h +++ b/Source/init.h @@ -3,7 +3,6 @@ #define __INIT_H__ extern _SNETVERSIONDATA fileinfo; -extern int init_cpp_init_value; // weak extern int gbActive; // weak extern char diablo_exe_path[260]; extern void *unused_mpq; diff --git a/Source/interfac.cpp b/Source/interfac.cpp index e16a04e4e..d59095b5d 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -3,22 +3,13 @@ #include "../types.h" void *sgpBackCel; -float interfac_cpp_init_value; +static float interfac_cpp_init_value = INFINITY; int sgdwProgress; int progress_id; // idb -const int interfac_inf = 0x7F800000; // weak const unsigned char progress_bar_colours[3] = { 138u, 43u, 254u }; const int progress_bar_screen_pos[3][2] = { { 53, 37 }, { 53, 421 }, { 53, 37 } }; -struct interfac_cpp_init { - interfac_cpp_init() - { - interfac_cpp_init_value = interfac_inf; - } -} _interfac_cpp_init; -// 47AE40: using guessed type int interfac_inf; - void __cdecl interface_msg_pump() { MSG Msg; // [esp+8h] [ebp-1Ch] diff --git a/Source/interfac.h b/Source/interfac.h index 1a2b8996e..db5abb04a 100644 --- a/Source/interfac.h +++ b/Source/interfac.h @@ -3,7 +3,6 @@ #define __INTERFAC_H__ extern void *sgpBackCel; -extern float interfac_cpp_init_value; extern int sgdwProgress; extern int progress_id; // idb diff --git a/Source/inv.cpp b/Source/inv.cpp index cfefdde02..c40e305f8 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -148,17 +148,18 @@ void __fastcall InvDrawSlotBack(int X, int Y, int W, int H) void __cdecl DrawInv() { BOOL invtest[40]; + int frame, frame_width, colour, screen_x, screen_y, i, j, ii; CelDecodeOnly(384, 511, pInvCels, 1, 320); if (plr[myplr].InvBody[INVLOC_HEAD]._itype != ITYPE_NONE) { InvDrawSlotBack(517, 219, 2 * INV_SLOT_SIZE_PX, 2 * INV_SLOT_SIZE_PX); - int frame = plr[myplr].InvBody[INVLOC_HEAD]._iCurs + 12; - int frame_width = InvItemWidth[frame]; + frame = plr[myplr].InvBody[INVLOC_HEAD]._iCurs + 12; + frame_width = InvItemWidth[frame]; if (pcursinvitem == INVITEM_HEAD) { - int colour = ICOL_WHITE; + colour = ICOL_WHITE; if (plr[myplr].InvBody[INVLOC_HEAD]._iMagical != ITEM_QUALITY_NORMAL) { colour = ICOL_BLUE; } @@ -178,11 +179,11 @@ void __cdecl DrawInv() if (plr[myplr].InvBody[INVLOC_RING_LEFT]._itype != ITYPE_NONE) { InvDrawSlotBack(432, 365, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); - int frame = plr[myplr].InvBody[INVLOC_RING_LEFT]._iCurs + 12; - int frame_width = InvItemWidth[frame]; + frame = plr[myplr].InvBody[INVLOC_RING_LEFT]._iCurs + 12; + frame_width = InvItemWidth[frame]; if (pcursinvitem == INVITEM_RING_LEFT) { - int colour = ICOL_WHITE; + colour = ICOL_WHITE; if (plr[myplr].InvBody[INVLOC_RING_LEFT]._iMagical != ITEM_QUALITY_NORMAL) { colour = ICOL_BLUE; } @@ -202,11 +203,11 @@ void __cdecl DrawInv() if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._itype != ITYPE_NONE) { InvDrawSlotBack(633, 365, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); - int frame = plr[myplr].InvBody[INVLOC_RING_RIGHT]._iCurs + 12; - int frame_width = InvItemWidth[frame]; + frame = plr[myplr].InvBody[INVLOC_RING_RIGHT]._iCurs + 12; + frame_width = InvItemWidth[frame]; if (pcursinvitem == INVITEM_RING_RIGHT) { - int colour = ICOL_WHITE; + colour = ICOL_WHITE; if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._iMagical != ITEM_QUALITY_NORMAL) { colour = ICOL_BLUE; } @@ -226,11 +227,11 @@ void __cdecl DrawInv() if (plr[myplr].InvBody[INVLOC_AMULET]._itype != ITYPE_NONE) { InvDrawSlotBack(589, 220, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); - int frame = plr[myplr].InvBody[INVLOC_AMULET]._iCurs + 12; - int frame_width = InvItemWidth[frame]; + frame = plr[myplr].InvBody[INVLOC_AMULET]._iCurs + 12; + frame_width = InvItemWidth[frame]; if (pcursinvitem == INVITEM_AMULET) { - int colour = ICOL_WHITE; + colour = ICOL_WHITE; if (plr[myplr].InvBody[INVLOC_AMULET]._iMagical != ITEM_QUALITY_NORMAL) { colour = ICOL_BLUE; } @@ -250,14 +251,14 @@ void __cdecl DrawInv() if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_NONE) { InvDrawSlotBack(401, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); - int frame = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCurs + 12; - int frame_width = InvItemWidth[frame]; + frame = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCurs + 12; + frame_width = InvItemWidth[frame]; // calc item offsets for weapons smaller than 2x3 slots - int screen_x = frame_width == INV_SLOT_SIZE_PX ? 415 : 401; - int screen_y = InvItemHeight[frame] == (3 * INV_SLOT_SIZE_PX) ? 320 : 306; + screen_x = frame_width == INV_SLOT_SIZE_PX ? 415 : 401; + screen_y = InvItemHeight[frame] == (3 * INV_SLOT_SIZE_PX) ? 320 : 306; if (pcursinvitem == INVITEM_HAND_LEFT) { - int colour = ICOL_WHITE; + colour = ICOL_WHITE; if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMagical != ITEM_QUALITY_NORMAL) { colour = ICOL_BLUE; } @@ -290,14 +291,14 @@ void __cdecl DrawInv() if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_NONE) { InvDrawSlotBack(631, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); - int frame = plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iCurs + 12; - int frame_width = InvItemWidth[frame]; + frame = plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iCurs + 12; + frame_width = InvItemWidth[frame]; // calc item offsets for weapons smaller than 2x3 slots - int screen_x = frame_width == INV_SLOT_SIZE_PX ? 645 : 633; - int screen_y = InvItemHeight[frame] == 3 * INV_SLOT_SIZE_PX ? 320 : 306; + screen_x = frame_width == INV_SLOT_SIZE_PX ? 645 : 633; + screen_y = InvItemHeight[frame] == 3 * INV_SLOT_SIZE_PX ? 320 : 306; if (pcursinvitem == INVITEM_HAND_RIGHT) { - int colour = ICOL_WHITE; + colour = ICOL_WHITE; if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iMagical != ITEM_QUALITY_NORMAL) { colour = ICOL_BLUE; } @@ -317,11 +318,11 @@ void __cdecl DrawInv() if (plr[myplr].InvBody[INVLOC_CHEST]._itype != ITYPE_NONE) { InvDrawSlotBack(517, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); - int frame = plr[myplr].InvBody[INVLOC_CHEST]._iCurs + 12; - int frame_width = InvItemWidth[frame]; + frame = plr[myplr].InvBody[INVLOC_CHEST]._iCurs + 12; + frame_width = InvItemWidth[frame]; if (pcursinvitem == INVITEM_CHEST) { - int colour = ICOL_WHITE; + colour = ICOL_WHITE; if (plr[myplr].InvBody[INVLOC_CHEST]._iMagical != ITEM_QUALITY_NORMAL) { colour = ICOL_BLUE; } @@ -338,7 +339,7 @@ void __cdecl DrawInv() } } - for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { + for (i = 0; i < NUM_INV_GRID_ELEM; i++) { if (plr[myplr].InvGrid[i] != 0) { InvDrawSlotBack( InvRect[i + SLOTXY_INV_FIRST].X + 64, @@ -348,17 +349,17 @@ void __cdecl DrawInv() } } - for (int j = 0; j < NUM_INV_GRID_ELEM; j++) { + for (j = 0; j < NUM_INV_GRID_ELEM; j++) { if (plr[myplr].InvGrid[j] > 0) // first slot of an item { - int ii = plr[myplr].InvGrid[j] - 1; + ii = plr[myplr].InvGrid[j] - 1; invtest[j] = TRUE; - int frame = plr[myplr].InvList[ii]._iCurs + 12; - int frame_width = InvItemWidth[frame]; + frame = plr[myplr].InvList[ii]._iCurs + 12; + frame_width = InvItemWidth[frame]; if (pcursinvitem == ii + INVITEM_INV_FIRST) { - int colour = ICOL_WHITE; + colour = ICOL_WHITE; if (plr[myplr].InvList[ii]._iMagical != ITEM_QUALITY_NORMAL) { colour = ICOL_BLUE; } @@ -1376,9 +1377,11 @@ LABEL_81: void __fastcall CheckInvSwap(int pnum, BYTE bLoc, int idx, WORD wCI, int seed, BOOL bId) { + PlayerStruct *p; + RecreateItem(MAXITEMS, idx, wCI, seed, 0); - PlayerStruct *p = &plr[pnum]; + p = &plr[pnum]; p->HoldItem = item[MAXITEMS]; if (bId) { @@ -1400,6 +1403,11 @@ void __fastcall CheckInvSwap(int pnum, BYTE bLoc, int idx, WORD wCI, int seed, B void __fastcall CheckInvCut(int pnum, int mx, int my) { + int r; + BOOL done; + char ii; + int iv, i, j, offs; + if (plr[pnum]._pmode > PM_WALK3) { return; } @@ -1409,8 +1417,7 @@ void __fastcall CheckInvCut(int pnum, int mx, int my) dropGoldValue = 0; } - int r; - BOOL done = FALSE; + done = FALSE; // TODO: this loop is compiled differently (via InvRect pointers) for (r = 0; (DWORD)r < NUM_XY_SLOTS && !done; r++) { @@ -1492,14 +1499,14 @@ void __fastcall CheckInvCut(int pnum, int mx, int my) } if (r >= SLOTXY_INV_FIRST && r <= SLOTXY_INV_LAST) { - char ii = plr[pnum].InvGrid[r - SLOTXY_INV_FIRST]; + ii = plr[pnum].InvGrid[r - SLOTXY_INV_FIRST]; if (ii) { - int iv = ii; + iv = ii; if (ii <= 0) { iv = -ii; } - for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { + for (i = 0; i < NUM_INV_GRID_ELEM; i++) { if (plr[pnum].InvGrid[i] == iv || plr[pnum].InvGrid[i] == -iv) { plr[pnum].InvGrid[i] = 0; } @@ -1513,7 +1520,7 @@ void __fastcall CheckInvCut(int pnum, int mx, int my) if (plr[pnum]._pNumInv > 0 && plr[pnum]._pNumInv != iv) { plr[pnum].InvList[iv] = plr[pnum].InvList[plr[pnum]._pNumInv]; - for (int j = 0; j < NUM_INV_GRID_ELEM; j++) { + for (j = 0; j < NUM_INV_GRID_ELEM; j++) { if (plr[pnum].InvGrid[j] == plr[pnum]._pNumInv + 1) { plr[pnum].InvGrid[j] = iv + 1; } @@ -1526,7 +1533,7 @@ void __fastcall CheckInvCut(int pnum, int mx, int my) } if (r >= SLOTXY_BELT_FIRST) { - int offs = r - SLOTXY_BELT_FIRST; + offs = r - SLOTXY_BELT_FIRST; if (plr[pnum].SpdList[offs]._itype != ITYPE_NONE) { plr[pnum].HoldItem = plr[pnum].SpdList[offs]; plr[pnum].SpdList[offs]._itype = ITYPE_NONE; @@ -1552,11 +1559,13 @@ void __fastcall CheckInvCut(int pnum, int mx, int my) void __fastcall inv_update_rem_item(int pnum, BYTE iv) { + BOOL Loadgfx; + if (iv < NUM_INVLOC) { plr[pnum].InvBody[iv]._itype = ITYPE_NONE; } - BOOL Loadgfx = FALSE; + Loadgfx = FALSE; if (plr[pnum]._pmode != PM_DEATH) { Loadgfx = TRUE; @@ -1567,9 +1576,11 @@ void __fastcall inv_update_rem_item(int pnum, BYTE iv) void __fastcall RemoveInvItem(int pnum, int iv) { + int i, j; + iv++; - for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { + for (i = 0; i < NUM_INV_GRID_ELEM; i++) { if (plr[pnum].InvGrid[i] == iv || plr[pnum].InvGrid[i] == -iv) { plr[pnum].InvGrid[i] = 0; } @@ -1581,7 +1592,7 @@ void __fastcall RemoveInvItem(int pnum, int iv) if (plr[pnum]._pNumInv > 0 && plr[pnum]._pNumInv != iv) { plr[pnum].InvList[iv] = plr[pnum].InvList[plr[pnum]._pNumInv]; - for (int j = 0; j < NUM_INV_GRID_ELEM; j++) { + for (j = 0; j < NUM_INV_GRID_ELEM; j++) { if (plr[pnum].InvGrid[j] == plr[pnum]._pNumInv + 1) { plr[pnum].InvGrid[j] = iv + 1; } diff --git a/Source/items.cpp b/Source/items.cpp index aa24c4f29..de3db4cd5 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -745,6 +745,8 @@ void __cdecl InitItems() void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx) { + int pvid, d; + int mind = 0; // min damage int maxd = 0; // max damage int tac = 0; // accuracy @@ -866,7 +868,7 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx) if (plr[p]._pLightRad != lrad && p == myplr) { ChangeLightRadius(plr[p]._plid, lrad); - int pvid = plr[p]._pvid; + pvid = plr[p]._pvid; if (lrad >= 10) { ChangeVisionRadius(pvid, lrad); } else { @@ -1032,7 +1034,7 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx) LoadPlrGFX(p, PFILE_STAND); SetPlrAnims(p); - int d = plr[p]._pdir; + d = plr[p]._pdir; // TODO: Add debug assert here ( plr[p]._pNAnim[d] != NULL ) plr[p]._pAnimData = plr[p]._pNAnim[d]; @@ -1061,15 +1063,17 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx) void __fastcall CalcPlrScrolls(int p) { + int i, j; + plr[p]._pScrlSpells = 0; - for (int i = 0; i < plr[p]._pNumInv; i++) { + for (i = 0; i < plr[p]._pNumInv; i++) { if (plr[p].InvList[i]._itype != ITYPE_NONE && (plr[p].InvList[i]._iMiscId == IMISC_SCROLL || plr[p].InvList[i]._iMiscId == IMISC_SCROLLT)) { if (plr[p].InvList[i]._iStatFlag) plr[p]._pScrlSpells |= (__int64)1 << (plr[p].InvList[i]._iSpell - 1); } } - for (int j = 0; j < MAXBELTITEMS; j++) { + for (j = 0; j < MAXBELTITEMS; j++) { if (plr[p].SpdList[j]._itype != ITYPE_NONE && (plr[p].SpdList[j]._iMiscId == IMISC_SCROLL || plr[p].SpdList[j]._iMiscId == IMISC_SCROLLT)) { if (plr[p].SpdList[j]._iStatFlag) plr[p]._pScrlSpells |= (__int64)1 << (plr[p].SpdList[j]._iSpell - 1); diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index fec5e68b2..1d3ecfc52 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -9,11 +9,13 @@ void __fastcall LoadGame(BOOL firstflag) int i, j; DWORD dwLen; char szName[MAX_PATH]; + BYTE *LoadBuff; + int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects; FreeGameMem(); pfile_remove_temp_files(); pfile_get_game_name(szName); - BYTE *LoadBuff = pfile_read(szName, &dwLen); + LoadBuff = pfile_read(szName, &dwLen); tbuff = LoadBuff; if (ILoad() != 'RETL') @@ -23,14 +25,14 @@ void __fastcall LoadGame(BOOL firstflag) setlvlnum = WLoad(); currlevel = WLoad(); leveltype = WLoad(); - int _ViewX = WLoad(); - int _ViewY = WLoad(); + _ViewX = WLoad(); + _ViewY = WLoad(); invflag = OLoad(); chrflag = OLoad(); - int _nummonsters = WLoad(); - int _numitems = WLoad(); - int _nummissiles = WLoad(); - int _nobjects = WLoad(); + _nummonsters = WLoad(); + _numitems = WLoad(); + _nummissiles = WLoad(); + _nobjects = WLoad(); for (i = 0; i < NUMLEVELS; i++) { glSeedTbl[i] = ILoad(); @@ -515,12 +517,14 @@ void __cdecl SaveLevel() { int i, j; char szName[MAX_PATH]; + int dwLen; + unsigned char *SaveBuff; if (!currlevel) glSeedTbl[0] = GetRndSeed(); - int dwLen = codec_get_encoded_len(FILEBUFF); - unsigned char *SaveBuff = DiabloAllocPtr(dwLen); + dwLen = codec_get_encoded_len(FILEBUFF); + SaveBuff = DiabloAllocPtr(dwLen); tbuff = SaveBuff; if (leveltype) { @@ -607,9 +611,10 @@ void __cdecl LoadLevel() int i, j; DWORD dwLen; char szName[MAX_PATH]; + BYTE *LoadBuff; GetPermLevelNames(szName); - BYTE *LoadBuff = pfile_read(szName, &dwLen); + LoadBuff = pfile_read(szName, &dwLen); tbuff = LoadBuff; if (leveltype) { diff --git a/Source/logging.cpp b/Source/logging.cpp index 3b2d001eb..128ca724d 100644 --- a/Source/logging.cpp +++ b/Source/logging.cpp @@ -2,29 +2,18 @@ #include "../types.h" -int log_cpp_init_value; // weak +static float log_cpp_init_value = INFINITY; static CRITICAL_SECTION sgMemCrit; CHAR FileName[260]; // idb char log_buffer[388]; LPCVOID lpAddress; // idb DWORD nNumberOfBytesToWrite; // idb -const int log_inf = 0x7F800000; // weak - /* data */ 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; - } -} _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() { diff --git a/Source/logging.h b/Source/logging.h index 4b5b2ee77..195c1decc 100644 --- a/Source/logging.h +++ b/Source/logging.h @@ -2,7 +2,6 @@ #ifndef __LOGGING_H__ #define __LOGGING_H__ -extern int log_cpp_init_value; // weak extern CHAR FileName[260]; // idb extern char log_buffer[388]; extern LPCVOID lpAddress; // idb diff --git a/Source/mainmenu.cpp b/Source/mainmenu.cpp index 24fcbfd29..066760cd8 100644 --- a/Source/mainmenu.cpp +++ b/Source/mainmenu.cpp @@ -130,12 +130,14 @@ BOOL __cdecl mainmenu_single_player() BOOL __fastcall mainmenu_init_menu(int type) { + BOOL success; + if (type == 4) return TRUE; music_stop(); - BOOL success = StartGame(type != 2, type != 3); + success = StartGame(type != 2, type != 3); if (success) mainmenu_refresh_music(); diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 3f20b18a0..62888e6a2 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -821,6 +821,7 @@ BOOL __fastcall MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, i int v15; // [esp+10h] [ebp-Ch] signed int v16; // [esp+14h] [ebp-8h] signed int arglist; // [esp+18h] [ebp-4h] + BOOL ret; v16 = 0; arglist = m; @@ -850,7 +851,6 @@ BOOL __fastcall MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, i if (v10 > 95) v10 = 95; //_LOBYTE(v11) = CheckMonsterHit(arglist, (unsigned char *)&t); - BOOL ret; if (CheckMonsterHit(arglist, &ret)) return ret; #ifdef _DEBUG diff --git a/Source/monster.cpp b/Source/monster.cpp index b3a220182..7b3e0465a 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -5,7 +5,7 @@ // Tracks which missile files are already loaded int MissileFileFlag; -int monster_cpp_init_value; // weak +static float monster_cpp_init_value = INFINITY; int monstkills[MAXMONSTERS]; int monstactive[MAXMONSTERS]; int nummonsters; @@ -18,7 +18,6 @@ int monstimgtot; // weak int uniquetrans; int nummtypes; -const int monster_inf = 0x7F800000; // weak const char plr2monst[9] = { 0, 5, 3, 7, 1, 4, 6, 0, 2 }; const unsigned char counsmiss[4] = { MIS_FIREBOLT, MIS_CBOLT, MIS_LIGHTCTRL, MIS_FIREBALL }; @@ -349,15 +348,6 @@ void(__fastcall *AiProc[])(int i) = { &MAI_Warlord }; -struct monster_cpp_init { - monster_cpp_init() - { - monster_cpp_init_value = monster_inf; - } -} _monster_cpp_init; -// 47F130: using guessed type int monster_inf; -// 64CCE4: using guessed type int monster_cpp_init_value; - void __fastcall InitMonsterTRN(int monst, BOOL special) { BYTE *f; diff --git a/Source/monster.h b/Source/monster.h index 93904a49c..f139893f6 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -2,8 +2,7 @@ #ifndef __MONSTER_H__ #define __MONSTER_H__ -extern int MissileFileFlag; // weak -extern int monster_cpp_init_value; // weak +extern int MissileFileFlag; // weak extern int monstkills[MAXMONSTERS]; extern int monstactive[MAXMONSTERS]; extern int nummonsters; @@ -165,7 +164,6 @@ void __fastcall decode_enemy(int m, int enemy); /* rdata */ -extern const int monster_inf; // weak extern const char plr2monst[9]; extern const unsigned char counsmiss[4]; diff --git a/Source/movie.cpp b/Source/movie.cpp index 30c0213ca..df22ea9b7 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -2,28 +2,20 @@ #include "../types.h" -int movie_cpp_init_value; // weak +static float movie_cpp_init_value = INFINITY; BYTE movie_playing; BOOL loop_movie; -const int movie_inf = 0x7F800000; // weak - -struct movie_cpp_init { - movie_cpp_init() - { - movie_cpp_init_value = movie_inf; - } -} _movie_cpp_init; -// 47F144: using guessed type int movie_inf; -// 659AF4: using guessed type int movie_cpp_init_value; - void __fastcall play_movie(char *pszMovie, BOOL user_can_close) { + WNDPROC saveProc; + void *video_stream; + if (!gbActive) { return; } - WNDPROC saveProc = SetWindowProc(MovieWndProc); + saveProc = SetWindowProc(MovieWndProc); InvalidateRect(ghMainWnd, 0, 0); UpdateWindow(ghMainWnd); movie_playing = TRUE; @@ -31,7 +23,6 @@ void __fastcall play_movie(char *pszMovie, BOOL user_can_close) sfx_stop(); effects_play_sound("Sfx\\Misc\\blank.wav"); - void *video_stream; SVidPlayBegin(pszMovie, 0, 0, 0, 0, loop_movie ? 0x100C0808 : 0x10280808, &video_stream); if (video_stream) { MSG Msg; diff --git a/Source/movie.h b/Source/movie.h index 3a0d08a5e..735d8c660 100644 --- a/Source/movie.h +++ b/Source/movie.h @@ -2,7 +2,6 @@ #ifndef __MOVIE_H__ #define __MOVIE_H__ -extern int movie_cpp_init_value; // weak extern BYTE movie_playing; extern BOOL loop_movie; @@ -12,6 +11,4 @@ LRESULT __stdcall MovieWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam /* rdata */ -extern const int movie_inf; // weak - #endif /* __MOVIE_H__ */ diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 41cc94464..e02062be0 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -2,31 +2,20 @@ #include "../types.h" -int mpqapi_cpp_init_value; // weak -int sgdwMpqOffset; // idb +static float mpqapi_cpp_init_value = INFINITY; +int sgdwMpqOffset; // idb char mpq_buf[4096]; _HASHENTRY *sgpHashTbl; BOOLEAN save_archive_modified; // weak _BLOCKENTRY *sgpBlockTbl; BOOLEAN save_archive_open; // weak -const int mpqapi_inf = 0x7F800000; // weak - //note: 32872 = 32768 + 104 (sizeof(_FILEHEADER)) /* data */ HANDLE sghArchive = (HANDLE)0xFFFFFFFF; // idb -struct mpqapi_cpp_init { - mpqapi_cpp_init() - { - mpqapi_cpp_init_value = mpqapi_inf; - } -} _mpqapi_cpp_init; -// 47F148: using guessed type int mpqapi_inf; -// 659B00: using guessed type int mpqapi_cpp_init_value; - BOOLEAN __fastcall mpqapi_set_hidden(const char *pszArchive, BOOLEAN hidden) { const char *v2; // edi diff --git a/Source/mpqapi.h b/Source/mpqapi.h index 50182d4c9..c180b7932 100644 --- a/Source/mpqapi.h +++ b/Source/mpqapi.h @@ -2,7 +2,6 @@ #ifndef __MPQAPI_H__ #define __MPQAPI_H__ -extern int mpqapi_cpp_init_value; // weak extern int sgdwMpqOffset; // idb extern char mpq_buf[4096]; extern _HASHENTRY *sgpHashTbl; @@ -42,8 +41,6 @@ BOOLEAN __cdecl mpqapi_can_seek(); /* rdata */ -extern const int mpqapi_inf; // weak - /* data */ extern HANDLE sghArchive; // idb diff --git a/Source/msgcmd.cpp b/Source/msgcmd.cpp index 2e0c08ede..8740c3ef6 100644 --- a/Source/msgcmd.cpp +++ b/Source/msgcmd.cpp @@ -4,21 +4,10 @@ /* TODO: decompile and fix, commands are NOT deleted properly */ -int msgcmd_cpp_init_value; // weak +static float msgcmd_cpp_init_value = INFINITY; ChatCmd sgChat_Cmd; int sgdwMsgCmdTimer; -const int msgcmd_inf = 0x7F800000; // weak - -struct msgcmd_cpp_init_1 { - msgcmd_cpp_init_1() - { - msgcmd_cpp_init_value = msgcmd_inf; - } -} _msgcmd_cpp_init_1; -// 47F150: using guessed type int msgcmd_inf; -// 6761A0: using guessed type int msgcmd_cpp_init_value; - struct msgcmd_cpp_init_2 { msgcmd_cpp_init_2() { diff --git a/Source/msgcmd.h b/Source/msgcmd.h index b9626bf30..2a859be5c 100644 --- a/Source/msgcmd.h +++ b/Source/msgcmd.h @@ -2,7 +2,6 @@ #ifndef __MSGCMD_H__ #define __MSGCMD_H__ -extern int msgcmd_cpp_init_value; // weak extern ChatCmd sgChat_Cmd; extern int sgdwMsgCmdTimer; @@ -26,6 +25,4 @@ void __fastcall msgcmd_cleanup_extern_msg(ServerCommand **extern_msgs); /* rdata */ -extern const int msgcmd_inf; // weak - #endif /* __MSGCMD_H__ */ diff --git a/Source/multi.cpp b/Source/multi.cpp index 170c31ee8..a153695f0 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -9,7 +9,7 @@ short sgwPackPlrOffsetTbl[MAX_PLRS]; PkPlayerStruct netplr[MAX_PLRS]; char sgbPlayerTurnBitTbl[MAX_PLRS]; char sgbPlayerLeftGameTbl[MAX_PLRS]; -int multi_cpp_init_value; // weak +static float multi_cpp_init_value = INFINITY; int sgbSentThisCycle; // idb int dword_678628; // weak BYTE gbActivePlayers; // weak @@ -28,22 +28,12 @@ BYTE gbDeltaSender; int sgbNetInited; // weak int player_state[MAX_PLRS]; -const int multi_inf = 0x7F800000; // weak const int event_types[3] = { EVENT_TYPE_PLAYER_LEAVE_GAME, EVENT_TYPE_PLAYER_CREATE_GAME, EVENT_TYPE_PLAYER_MESSAGE }; -struct multi_cpp_init { - multi_cpp_init() - { - multi_cpp_init_value = multi_inf; - } -} _multi_cpp_init; -// 47F154: using guessed type int multi_inf; -// 678620: using guessed type int multi_cpp_init_value; - void __fastcall multi_msg_add(BYTE *a1, unsigned char a2) { if (a1) { diff --git a/Source/multi.h b/Source/multi.h index d6f97b0bb..aecf2dc31 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -9,7 +9,6 @@ extern short sgwPackPlrOffsetTbl[MAX_PLRS]; extern PkPlayerStruct netplr[MAX_PLRS]; extern char sgbPlayerTurnBitTbl[MAX_PLRS]; extern char sgbPlayerLeftGameTbl[MAX_PLRS]; -extern int multi_cpp_init_value; // weak extern int sgbSentThisCycle; // idb extern int dword_678628; // weak extern BYTE gbActivePlayers; diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 6ffafed64..dcb8f7deb 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -2,8 +2,8 @@ #include "../types.h" -int nthread_cpp_init_value; // weak -char byte_679704; // weak +static float nthread_cpp_init_value = INFINITY; +char byte_679704; // weak int gdwMsgLenTbl[4]; static CRITICAL_SECTION sgMemCrit; int gdwDeltaBytesSec; // weak @@ -20,20 +20,9 @@ int gdwLargestMsgSize; // weak int gdwNormalMsgSize; // weak int last_tick; // weak -const int nthread_inf = 0x7F800000; // weak - /* data */ static HANDLE sghThread = (HANDLE)0xFFFFFFFF; // idb -struct nthread_cpp_init_1 { - nthread_cpp_init_1() - { - nthread_cpp_init_value = nthread_inf; - } -} _nthread_cpp_init_1; -// 47F164: using guessed type int nthread_inf; -// 679700: using guessed type int nthread_cpp_init_value; - struct nthread_cpp_init_2 { nthread_cpp_init_2() { diff --git a/Source/nthread.h b/Source/nthread.h index c90c7bf8e..cf8bffc39 100644 --- a/Source/nthread.h +++ b/Source/nthread.h @@ -2,7 +2,6 @@ #ifndef __NTHREAD_H__ #define __NTHREAD_H__ -extern int nthread_cpp_init_value; // weak extern char byte_679704; // weak extern int gdwMsgLenTbl[4]; extern int gdwDeltaBytesSec; // weak @@ -34,6 +33,4 @@ BOOL __fastcall nthread_has_500ms_passed(BOOL unused); /* rdata */ -extern const int nthread_inf; // weak - #endif /* __NTHREAD_H__ */ diff --git a/Source/pack.cpp b/Source/pack.cpp index 8c27e10e7..bdefd4a06 100644 --- a/Source/pack.cpp +++ b/Source/pack.cpp @@ -2,18 +2,7 @@ #include "../types.h" -int pack_cpp_init_value; // weak - -const int pack_inf = 0x7F800000; // weak - -struct pack_cpp_init { - pack_cpp_init() - { - pack_cpp_init_value = pack_inf; - } -} _pack_cpp_init; -// 47F168: using guessed type int pack_inf; -// 67D7C8: using guessed type int pack_cpp_init_value; +static float pack_cpp_init_value = INFINITY; void __fastcall PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield) { diff --git a/Source/pack.h b/Source/pack.h index bc1c7aba0..25d2da8be 100644 --- a/Source/pack.h +++ b/Source/pack.h @@ -2,8 +2,6 @@ #ifndef __PACK_H__ #define __PACK_H__ -extern int pack_cpp_init_value; // weak - void __cdecl pack_cpp_init(); void __fastcall PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield); void __fastcall PackItem(PkItemStruct *id, ItemStruct *is); @@ -13,6 +11,4 @@ void __fastcall UnPackItem(PkItemStruct *is, ItemStruct *id); /* rdata */ -extern const int pack_inf; // weak - #endif /* __PACK_H__ */ diff --git a/Source/palette.cpp b/Source/palette.cpp index 499c3d373..b7eaf460e 100644 --- a/Source/palette.cpp +++ b/Source/palette.cpp @@ -3,28 +3,17 @@ #include "../types.h" PALETTEENTRY logical_palette[256]; -int palette_cpp_init_value; // weak +static float palette_cpp_init_value = INFINITY; PALETTEENTRY system_palette[256]; PALETTEENTRY orig_palette[256]; UINT gdwPalEntries; -const int palette_inf = 0x7F800000; // weak - /* data */ int gamma_correction = 100; // idb BOOL color_cycling_enabled = TRUE; BOOLEAN sgbFadedIn = 1; -struct palette_cpp_init { - palette_cpp_init() - { - palette_cpp_init_value = palette_inf; - } -} _palette_cpp_init; -// 47F16C: using guessed type int palette_inf; -// 67DBCC: using guessed type int palette_cpp_init_value; - void __cdecl SaveGamma() { SRegSaveValue("Diablo", "Gamma Correction", 0, gamma_correction); diff --git a/Source/palette.h b/Source/palette.h index 565a5d0b6..4c2f7eb87 100644 --- a/Source/palette.h +++ b/Source/palette.h @@ -3,7 +3,6 @@ #define __PALETTE_H__ extern PALETTEENTRY logical_palette[256]; -extern int palette_cpp_init_value; // weak extern PALETTEENTRY system_palette[256]; extern PALETTEENTRY orig_palette[256]; extern UINT gdwPalEntries; @@ -32,8 +31,6 @@ void __fastcall palette_set_color_cycling(BOOLEAN enabled); /* rdata */ -extern const int palette_inf; // weak - /* data */ extern int gamma_correction; // idb diff --git a/Source/path.cpp b/Source/path.cpp index 0805fe824..5ce8858fc 100644 --- a/Source/path.cpp +++ b/Source/path.cpp @@ -362,10 +362,12 @@ PATHNODE *__cdecl path_pop_active_step() * none are available */ PATHNODE *__cdecl path_new_step() { + PATHNODE *new_node; + if (gdwCurNodes == MAXPATHNODES) return NULL; - PATHNODE *new_node = &path_nodes[gdwCurNodes]; + new_node = &path_nodes[gdwCurNodes]; gdwCurNodes++; memset(new_node, 0, sizeof(PATHNODE)); return new_node; diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 6cb92dec0..6ae1354c7 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -315,14 +315,16 @@ char *__fastcall GetSaveDirectory(char *dst, int dst_size, unsigned int save_num BOOL __fastcall pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack) { HANDLE file; + BOOL decoded, ret; + DWORD dwlen, nSize; + unsigned char *buf; if (!SFileOpenFileEx(archive, "hero", 0, &file)) return FALSE; else { - DWORD dwlen; - BOOL ret = FALSE; + ret = FALSE; char password[16] = PASSWORD_SINGLE; - DWORD nSize = 16; + nSize = 16; if (gbMaxPlayers > 1) strcpy(password, PASSWORD_MULTI); @@ -330,9 +332,9 @@ BOOL __fastcall pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack) dwlen = SFileGetFileSize(file, NULL); if (dwlen) { DWORD read; - unsigned char *buf = DiabloAllocPtr(dwlen); + buf = DiabloAllocPtr(dwlen); if (SFileReadFile(file, buf, dwlen, &read, NULL)) { - BOOL decoded = TRUE; + decoded = TRUE; read = codec_decode(buf, dwlen, password); if (!read && gbMaxPlayers > 1) { GetComputerName(password, &nSize); @@ -422,7 +424,7 @@ BOOL __stdcall pfile_ui_save_create(_uiheroinfo *heroinfo) break; } if (save_num == MAX_CHARACTERS) - return false; + return FALSE; } if (!pfile_open_archive(FALSE, save_num)) return FALSE; diff --git a/Source/player.cpp b/Source/player.cpp index 2a3279d89..85e5e0509 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -5,7 +5,7 @@ int plr_lframe_size; int plr_wframe_size; UCHAR plr_gfx_flag = 0; -int player_cpp_init_value; +static float player_cpp_init_value = INFINITY; int plr_aframe_size; int myplr; PlayerStruct plr[MAX_PLRS]; @@ -19,7 +19,6 @@ int plr_sframe_size; int deathdelay; int plr_dframe_size; -const int player_inf = 0x7F800000; // weak const char ArmourChar[4] = { 'L', 'M', 'H', 0 }; const char WepChar[10] = { 'N', 'U', 'S', 'D', 'B', 'A', 'M', 'H', 'T', 0 }; const char CharChar[4] = { 'W', 'R', 'S', 0 }; @@ -108,14 +107,6 @@ int ExpLvlsTbl[MAXCHARLEVEL] = { char *ClassStrTbl[3] = { "Warrior", "Rogue", "Sorceror" }; unsigned char fix[9] = { 0u, 0u, 3u, 3u, 3u, 6u, 6u, 6u, 8u }; /* PM_ChangeLightOff local type */ -struct player_cpp_init { - player_cpp_init() - { - player_cpp_init_value = player_inf; - } -} _player_cpp_init; -// 47F204: using guessed type int player_inf; -// 68643C: using guessed type int player_cpp_init_value; void __fastcall SetPlayerGPtrs(UCHAR *pData, UCHAR **pAnim) { diff --git a/Source/player.h b/Source/player.h index 2c0677eef..8c8043a8b 100644 --- a/Source/player.h +++ b/Source/player.h @@ -5,7 +5,6 @@ extern int plr_lframe_size; // idb extern int plr_wframe_size; // idb extern UCHAR plr_gfx_flag; -extern int player_cpp_init_value; // weak extern int plr_aframe_size; // idb extern int myplr; extern PlayerStruct plr[MAX_PLRS]; @@ -113,7 +112,6 @@ void __cdecl PlayDungMsgs(); /* rdata */ -extern const int player_inf; extern const char ArmourChar[4]; extern const char WepChar[10]; extern const char CharChar[4];