Browse Source

C compatability from d-p (#519)

pull/25/head
Anders Jenbo 7 years ago committed by Robin Eklind
parent
commit
b5f69dccdc
  1. 92
      Source/effects.cpp
  2. 3
      Source/effects.h
  3. 76
      Source/encrypt.cpp
  4. 12
      Source/engine.cpp
  5. 1
      Source/engine.h
  6. 8
      Source/error.cpp
  7. 59
      Source/fault.cpp
  8. 4
      Source/gamemenu.cpp
  9. 13
      Source/init.cpp
  10. 1
      Source/init.h
  11. 11
      Source/interfac.cpp
  12. 1
      Source/interfac.h
  13. 95
      Source/inv.cpp
  14. 12
      Source/items.cpp
  15. 25
      Source/loadsave.cpp
  16. 13
      Source/logging.cpp
  17. 1
      Source/logging.h
  18. 4
      Source/mainmenu.cpp
  19. 2
      Source/missiles.cpp
  20. 12
      Source/monster.cpp
  21. 4
      Source/monster.h
  22. 19
      Source/movie.cpp
  23. 3
      Source/movie.h
  24. 15
      Source/mpqapi.cpp
  25. 3
      Source/mpqapi.h
  26. 13
      Source/msgcmd.cpp
  27. 3
      Source/msgcmd.h
  28. 12
      Source/multi.cpp
  29. 1
      Source/multi.h
  30. 15
      Source/nthread.cpp
  31. 3
      Source/nthread.h
  32. 13
      Source/pack.cpp
  33. 4
      Source/pack.h
  34. 13
      Source/palette.cpp
  35. 3
      Source/palette.h
  36. 4
      Source/path.cpp
  37. 14
      Source/pfile.cpp
  38. 11
      Source/player.cpp
  39. 2
      Source/player.h

92
Source/effects.cpp

@ -2,13 +2,12 @@
#include "../types.h" #include "../types.h"
int effects_cpp_init_value; // weak static float effects_cpp_init_value = INFINITY;
int sfxdelay; // weak int sfxdelay; // weak
int sfxdnum; int sfxdnum;
void *sfx_stream; void *sfx_stream;
TSFX *sfx_data_cur; TSFX *sfx_data_cur;
const int effects_inf = 0x7F800000; // weak
const char monster_action_sounds[] = { 'a', 'h', 'd', 's' }; // idb const char monster_action_sounds[] = { 'a', 'h', 'd', 's' }; // idb
/* data */ /* data */
@ -877,15 +876,6 @@ TSFX sgSFX[NUM_SFX] = {
// clang-format on // 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) BOOL __fastcall effect_is_playing(int nSFX)
{ {
TSFX *sfx = &sgSFX[nSFX]; TSFX *sfx = &sgSFX[nSFX];
@ -913,15 +903,16 @@ void __fastcall InitMonsterSND(int monst)
TSnd *pSnd; TSnd *pSnd;
char name[MAX_PATH]; char name[MAX_PATH];
char *path; char *path;
int mtype, i, j;
if (!gbSndInited) { if (!gbSndInited) {
return; return;
} }
int mtype = Monsters[monst].mtype; mtype = Monsters[monst].mtype;
for (int i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (monster_action_sounds[i] != 's' || monsterdata[mtype].snd_special) { 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); sprintf(name, monsterdata[mtype].sndfile, monster_action_sounds[i], j + 1);
path = (char *)DiabloAllocPtr(strlen(name) + 1); path = (char *)DiabloAllocPtr(strlen(name) + 1);
strcpy(path, name); strcpy(path, name);
@ -936,14 +927,18 @@ void __fastcall InitMonsterSND(int monst)
void __cdecl FreeEffects() void __cdecl FreeEffects()
{ {
for (int i = 0; i < nummtypes; i++) { int mtype, i, j, k;
int mtype = Monsters[i].mtype; char *file;
for (int j = 0; j < 4; ++j) { TSnd *pSnd;
for (int k = 0; k < 2; ++k) {
TSnd *pSnd = Monsters[i].Snds[j][k]; 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) { if (pSnd) {
Monsters[i].Snds[j][k] = NULL; Monsters[i].Snds[j][k] = NULL;
char *file = pSnd->sound_path; file = pSnd->sound_path;
pSnd->sound_path = NULL; pSnd->sound_path = NULL;
sound_file_cleanup(pSnd); sound_file_cleanup(pSnd);
mem_free_dbg(file); mem_free_dbg(file);
@ -955,22 +950,24 @@ void __cdecl FreeEffects()
void __fastcall PlayEffect(int i, int mode) void __fastcall PlayEffect(int i, int mode)
{ {
int sndIdx, mi, lVolume, lPan;
TSnd *snd;
if (plr[myplr].pLvlLoad) { if (plr[myplr].pLvlLoad) {
return; return;
} }
int sndIdx = random(164, 2); sndIdx = random(164, 2);
if (!gbSndInited || !gbSoundOn || gbBufferMsgs) { if (!gbSndInited || !gbSoundOn || gbBufferMsgs) {
return; return;
} }
int mi = monster[i]._mMTidx; mi = monster[i]._mMTidx;
TSnd *snd = Monsters[mi].Snds[mode][sndIdx]; snd = Monsters[mi].Snds[mode][sndIdx];
if (!snd || snd_playing(snd)) { if (!snd || snd_playing(snd)) {
return; return;
} }
int lVolume, lPan;
if (!calc_snd_position(monster[i]._mx, monster[i]._my, &lVolume, &lPan)) if (!calc_snd_position(monster[i]._mx, monster[i]._my, &lVolume, &lPan))
return; 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) BOOL __fastcall calc_snd_position(int x, int y, int *plVolume, int *plPan)
{ {
int pan, volume;
x -= plr[myplr].WorldX; x -= plr[myplr].WorldX;
y -= plr[myplr].WorldY; y -= plr[myplr].WorldY;
int pan = (x - y) << 8; pan = (x - y) << 8;
*plPan = pan; *plPan = pan;
if (abs(pan) > 6400) if (abs(pan) > 6400)
return FALSE; return FALSE;
int volume = abs(x) > abs(y) ? abs(x) : abs(y); volume = abs(x) > abs(y) ? abs(x) : abs(y);
volume <<= 6; volume <<= 6;
*plVolume = volume; *plVolume = volume;
@ -1009,6 +1008,8 @@ void __fastcall PlaySFX(int psfx)
void __fastcall PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y) void __fastcall PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y)
{ {
int lPan, lVolume;
if (plr[myplr].pLvlLoad && gbMaxPlayers != 1) { if (plr[myplr].pLvlLoad && gbMaxPlayers != 1) {
return; return;
} }
@ -1020,8 +1021,8 @@ void __fastcall PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y)
return; return;
} }
int lPan = 0; lPan = 0;
int lVolume = 0; lVolume = 0;
if (loc && !calc_snd_position(x, y, &lVolume, &lPan)) { if (loc && !calc_snd_position(x, y, &lVolume, &lPan)) {
return; 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) void __fastcall stream_play(TSFX *pSFX, int lVolume, int lPan)
{ {
BOOL success;
/// ASSERT: assert(pSFX); /// ASSERT: assert(pSFX);
/// ASSERT: assert(pSFX->bFlags & sfx_STREAM); /// ASSERT: assert(pSFX->bFlags & sfx_STREAM);
sfx_stop(); sfx_stop();
@ -1052,7 +1055,7 @@ void __fastcall stream_play(TSFX *pSFX, int lVolume, int lPan)
#ifdef _DEBUG #ifdef _DEBUG
SFileEnableDirectAccess(FALSE); SFileEnableDirectAccess(FALSE);
#endif #endif
BOOL success = SFileOpenFile(pSFX->pszName, &sfx_stream); success = SFileOpenFile(pSFX->pszName, &sfx_stream);
#ifdef _DEBUG #ifdef _DEBUG
SFileEnableDirectAccess(TRUE); SFileEnableDirectAccess(TRUE);
#endif #endif
@ -1101,10 +1104,12 @@ int __fastcall RndSFX(int psfx)
void __fastcall PlaySfxLoc(int psfx, int x, int y) void __fastcall PlaySfxLoc(int psfx, int x, int y)
{ {
TSnd *pSnd;
psfx = RndSFX(psfx); psfx = RndSFX(psfx);
if (psfx >= 0 && psfx <= 3) { if (psfx >= 0 && psfx <= 3) {
TSnd *pSnd = sgSFX[psfx].pSnd; pSnd = sgSFX[psfx].pSnd;
if (pSnd) if (pSnd)
pSnd->start_tc = 0; pSnd->start_tc = 0;
} }
@ -1114,13 +1119,15 @@ void __fastcall PlaySfxLoc(int psfx, int x, int y)
void __cdecl FreeMonsterSnd() void __cdecl FreeMonsterSnd()
{ {
int i, j, k;
snd_update(TRUE); snd_update(TRUE);
sfx_stop(); sfx_stop();
sound_stop(); sound_stop();
for (int i = 0; i < nummtypes; i++) { for (i = 0; i < nummtypes; i++) {
for (int j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
for (int k = 0; k < 2; k++) { for (k = 0; k < 2; k++) {
snd_stop_snd(Monsters[i].Snds[j][k]); snd_stop_snd(Monsters[i].Snds[j][k]);
} }
} }
@ -1164,9 +1171,11 @@ void __cdecl sound_update()
void __cdecl effects_cleanup_sfx() void __cdecl effects_cleanup_sfx()
{ {
DWORD i;
FreeMonsterSnd(); FreeMonsterSnd();
for (DWORD i = 0; i < NUM_SFX; i++) { for (i = 0; i < NUM_SFX; i++) {
if (sgSFX[i].pSnd) { if (sgSFX[i].pSnd) {
sound_file_cleanup(sgSFX[i].pSnd); sound_file_cleanup(sgSFX[i].pSnd);
sgSFX[i].pSnd = NULL; sgSFX[i].pSnd = NULL;
@ -1195,19 +1204,22 @@ void __cdecl stream_update()
void __fastcall priv_sound_init(UCHAR bLoadMask) void __fastcall priv_sound_init(UCHAR bLoadMask)
{ {
UCHAR pc, bFlags;
DWORD i;
if (!gbSndInited) { if (!gbSndInited) {
return; return;
} }
UCHAR pc = bLoadMask & (SFX_ROGUE | SFX_WARRIOR | SFX_SORCEROR); pc = bLoadMask & (SFX_ROGUE | SFX_WARRIOR | SFX_SORCEROR);
bLoadMask ^= pc; bLoadMask ^= pc;
for (DWORD i = 0; i < NUM_SFX; i++) { for (i = 0; i < NUM_SFX; i++) {
if (sgSFX[i].pSnd) { if (sgSFX[i].pSnd) {
continue; continue;
} }
UCHAR bFlags = sgSFX[i].bFlags; bFlags = sgSFX[i].bFlags;
if (bFlags & SFX_STREAM) { if (bFlags & SFX_STREAM) {
continue; continue;
} }
@ -1231,11 +1243,13 @@ void __cdecl sound_init()
void __stdcall effects_play_sound(char *snd_file) void __stdcall effects_play_sound(char *snd_file)
{ {
DWORD i;
if (!gbSndInited || !gbSoundOn) { if (!gbSndInited || !gbSoundOn) {
return; 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 (!_strcmpi(sgSFX[i].pszName, snd_file) && sgSFX[i].pSnd) {
if (!snd_playing(sgSFX[i].pSnd)) if (!snd_playing(sgSFX[i].pSnd))
snd_play_snd(sgSFX[i].pSnd, 0, 0); snd_play_snd(sgSFX[i].pSnd, 0, 0);

3
Source/effects.h

@ -2,8 +2,7 @@
#ifndef __EFFECTS_H__ #ifndef __EFFECTS_H__
#define __EFFECTS_H__ #define __EFFECTS_H__
extern int effects_cpp_init_value; // weak extern int sfxdelay; // weak
extern int sfxdelay; // weak
extern int sfxdnum; extern int sfxdnum;
extern void *sfx_stream; extern void *sfx_stream;
extern TSFX *sfx_data_cur; extern TSFX *sfx_data_cur;

76
Source/encrypt.cpp

@ -6,9 +6,12 @@ DWORD hashtable[1280];
void __fastcall Decrypt(void *block, DWORD size, DWORD key) void __fastcall Decrypt(void *block, DWORD size, DWORD key)
{ {
DWORD *castBlock = (DWORD *)block; DWORD *castBlock;
DWORD seed = 0xEEEEEEEE; DWORD seed, i;
for (DWORD i = 0; i < (size >> 2); i++) {
castBlock = (DWORD *)block;
seed = 0xEEEEEEEE;
for (i = 0; i < (size >> 2); i++) {
seed += hashtable[0x400 + (key & 0xFF)]; seed += hashtable[0x400 + (key & 0xFF)];
*castBlock ^= seed + key; *castBlock ^= seed + key;
seed += *castBlock + (seed << 5) + 3; 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) void __fastcall Encrypt(void *block, DWORD size, DWORD key)
{ {
DWORD *castBlock = (DWORD *)block; DWORD *castBlock;
DWORD seed = 0xEEEEEEEE; DWORD seed, i, ch;
for (DWORD i = 0; i < (size >> 2); i++) {
DWORD ch = *castBlock; castBlock = (DWORD *)block;
seed = 0xEEEEEEEE;
for (i = 0; i < (size >> 2); i++) {
ch = *castBlock;
seed += hashtable[0x400 + (key & 0xFF)]; seed += hashtable[0x400 + (key & 0xFF)];
*castBlock ^= seed + key; *castBlock ^= seed + key;
seed += ch + (seed << 5) + 3; 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) DWORD __fastcall Hash(const char *s, int type)
{ {
char ch; char ch;
DWORD seed1 = 0x7FED7FED; DWORD seed1, seed2;
DWORD seed2 = 0xEEEEEEEE;
seed1 = 0x7FED7FED;
seed2 = 0xEEEEEEEE;
while (s != NULL && *s) { while (s != NULL && *s) {
ch = *s++; ch = *s++;
ch = toupper(ch); ch = toupper(ch);
@ -47,12 +55,15 @@ DWORD __fastcall Hash(const char *s, int type)
void __cdecl InitHash() void __cdecl InitHash()
{ {
DWORD seed = 0x00100001; DWORD seed, ch;
int i, j;
seed = 0x00100001;
for (int i = 0; i < 256; i++) { for ( i = 0; i < 256; i++) {
for (int j = 0; j < 5; j++) { for ( j = 0; j < 5; j++) {
seed = (125 * seed + 3) % 0x2AAAAB; seed = (125 * seed + 3) % 0x2AAAAB;
DWORD ch = (seed & 0xFFFF); ch = (seed & 0xFFFF);
seed = (125 * seed + 3) % 0x2AAAAB; seed = (125 * seed + 3) % 0x2AAAAB;
hashtable[i + j * 256] = ch << 16 | (seed & 0xFFFF); hashtable[i + j * 256] = ch << 16 | (seed & 0xFFFF);
} }
@ -61,24 +72,28 @@ void __cdecl InitHash()
int __fastcall PkwareCompress(void *buf, int size) int __fastcall PkwareCompress(void *buf, int size)
{ {
BYTE *srcData = (BYTE *)buf; BYTE *srcData, *destData;
char *ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE); 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) if (destSize < 8192)
destSize = 8192; destSize = 8192;
BYTE *destData = (BYTE *)DiabloAllocPtr(destSize); destData = (BYTE *)DiabloAllocPtr(destSize);
TDataInfo param;
param.srcData = srcData; param.srcData = srcData;
param.srcOffset = 0; param.srcOffset = 0;
param.destData = destData; param.destData = destData;
param.destOffset = 0; param.destOffset = 0;
param.size = size; param.size = size;
unsigned int type = 0; type = 0;
unsigned int dsize = 4096; dsize = 4096;
implode(PkwareBufferRead, PkwareBufferWrite, ptr, &param, &type, &dsize); implode(PkwareBufferRead, PkwareBufferWrite, ptr, &param, &type, &dsize);
if (param.destOffset < size) { 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) unsigned int __cdecl PkwareBufferRead(char *buf, unsigned int *size, void *param)
{ {
TDataInfo *pInfo = (TDataInfo *)param; TDataInfo *pInfo;
DWORD sSize; DWORD sSize;
pInfo = (TDataInfo *)param;
if (*size >= pInfo->size - pInfo->srcOffset) { if (*size >= pInfo->size - pInfo->srcOffset) {
sSize = pInfo->size - pInfo->srcOffset; sSize = pInfo->size - pInfo->srcOffset;
} else { } 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) 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); memcpy(pInfo->destData + pInfo->destOffset, buf, *size);
pInfo->destOffset += *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) void __fastcall PkwareDecompress(void *param, int recv_size, int dwMaxBytes)
{ {
char *ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE); char *ptr;
BYTE *pbInBuff = (BYTE *)param; BYTE *pbInBuff, *pbOutBuff;
BYTE *pbOutBuff = DiabloAllocPtr(dwMaxBytes);
TDataInfo info; TDataInfo info;
ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE);
pbInBuff = (BYTE *)param;
pbOutBuff = DiabloAllocPtr(dwMaxBytes);
info.srcData = pbInBuff; info.srcData = pbInBuff;
info.srcOffset = 0; info.srcOffset = 0;
info.destData = pbOutBuff; info.destData = pbOutBuff;

12
Source/engine.cpp

@ -2,7 +2,7 @@
#include "../types.h" #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) char gbPixelCol; // automap pixel color 8-bit (palette entry)
int dword_52B970; // BOOLEAN flip - if y < x int dword_52B970; // BOOLEAN flip - if y < x
int orgseed; // weak int orgseed; // weak
@ -12,19 +12,9 @@ static CRITICAL_SECTION sgMemCrit;
int SeedCount; // weak int SeedCount; // weak
int dword_52B99C; // BOOLEAN valid - if x/y are in bounds 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_increment = 1; // unused
const int rand_multiplier = 0x015A4E35; // 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) void __fastcall CelDrawDatOnly(char *pDecodeTo, char *pRLEBytes, int dwRLESize, int dwRLEWdt)
{ {
char *v4; // esi char *v4; // esi

1
Source/engine.h

@ -5,7 +5,6 @@
//offset 0 //offset 0
//pCelBuff->pFrameTable[0] //pCelBuff->pFrameTable[0]
extern int engine_cpp_init_value; // weak
extern char gbPixelCol; // automap pixel color 8-bit (palette entry) extern char gbPixelCol; // automap pixel color 8-bit (palette entry)
extern int dword_52B970; // bool flip - if y < x extern int dword_52B970; // bool flip - if y < x
extern int orgseed; // weak extern int orgseed; // weak

8
Source/error.cpp

@ -56,7 +56,9 @@ char *MsgStrings[44] = {
void __fastcall InitDiabloMsg(char e) void __fastcall InitDiabloMsg(char e)
{ {
for (int i = 0; i < msgcnt; i++) { int i;
for (i = 0; i < msgcnt; i++) {
if (msgtable[i] == e) if (msgtable[i] == e)
return; return;
} }
@ -71,7 +73,9 @@ void __fastcall InitDiabloMsg(char e)
void __cdecl ClrDiabloMsg() void __cdecl ClrDiabloMsg()
{ {
for (int i = 0; i < sizeof(msgtable); i++) int i;
for (i = 0; i < sizeof(msgtable); i++)
msgtable[i] = 0; msgtable[i] = 0;
msgflag = 0; msgflag = 0;

59
Source/fault.cpp

@ -29,19 +29,22 @@ void __cdecl exception_init_filter()
LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo)
{ {
log_dump_computer_info(); PEXCEPTION_RECORD xcpt;
PEXCEPTION_RECORD xcpt = ExceptionInfo->ExceptionRecord;
char szExceptionNameBuf[MAX_PATH]; 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 szModuleName[MAX_PATH];
char *pszExceptionName;
int sectionNumber, sectionOffset; 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, &sectionNumber, &sectionOffset); exception_unknown_module(xcpt->ExceptionAddress, szModuleName, MAX_PATH, &sectionNumber, &sectionOffset);
log_printf("Fault address:\t%08X %02X:%08X %s\r\n", xcpt->ExceptionAddress, sectionNumber, sectionOffset, szModuleName); 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("\r\nRegisters:\r\n");
log_printf( log_printf(
@ -75,10 +78,11 @@ LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo)
void __fastcall exception_hex_format(BYTE *ptr, unsigned int numBytes) void __fastcall exception_hex_format(BYTE *ptr, unsigned int numBytes)
{ {
DWORD i; DWORD i, bytesRead;
const char *fmt;
BYTE c;
while (numBytes > 0) { while (numBytes > 0) {
DWORD bytesRead;
if (numBytes < 16) if (numBytes < 16)
bytesRead = numBytes; bytesRead = numBytes;
else else
@ -90,7 +94,7 @@ void __fastcall exception_hex_format(BYTE *ptr, unsigned int numBytes)
log_printf("0x%08x: ", ptr); log_printf("0x%08x: ", ptr);
for (i = 0; i < 16; ++i) { for (i = 0; i < 16; ++i) {
const char *fmt = "%02x "; fmt = "%02x ";
if (i >= bytesRead) if (i >= bytesRead)
fmt = " "; fmt = " ";
log_printf(fmt, ptr[i]); 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++) { for (i = 0; i < bytesRead; i++) {
BYTE c;
if (isprint(ptr[i])) if (isprint(ptr[i]))
c = ptr[i]; c = ptr[i];
else 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) 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); lstrcpyn(lpModuleName, "*unknown*", iMaxLength);
*sectionNum = 0; *sectionNum = 0;
*sectionOffset = 0; *sectionOffset = 0;
MEMORY_BASIC_INFORMATION memInfo;
if (!VirtualQuery(lpAddress, &memInfo, sizeof(memInfo))) if (!VirtualQuery(lpAddress, &memInfo, sizeof(memInfo)))
return; return;
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)memInfo.AllocationBase; dosHeader = (PIMAGE_DOS_HEADER)memInfo.AllocationBase;
if (!memInfo.AllocationBase) if (!memInfo.AllocationBase)
dosHeader = (PIMAGE_DOS_HEADER)GetModuleHandle(0); 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) { if (dosHeader && dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
LONG ntOffset = dosHeader->e_lfanew; ntOffset = dosHeader->e_lfanew;
if (ntOffset) { 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) { if (ntHeader->Signature == IMAGE_NT_SIGNATURE) {
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(ntHeader); section = IMAGE_FIRST_SECTION(ntHeader);
DWORD numSections = ntHeader->FileHeader.NumberOfSections; numSections = ntHeader->FileHeader.NumberOfSections;
DWORD moduleOffset = (BYTE *)lpAddress - (BYTE *)dosHeader; moduleOffset = (BYTE *)lpAddress - (BYTE *)dosHeader;
for (int i = 0; i < numSections; i++, section++) { for (i = 0; i < numSections; i++, section++) {
DWORD sectionSize = section->SizeOfRawData; sectionSize = section->SizeOfRawData;
DWORD sectionAddress = section->VirtualAddress; sectionAddress = section->VirtualAddress;
if (section->SizeOfRawData <= section->Misc.VirtualSize) if (section->SizeOfRawData <= section->Misc.VirtualSize)
sectionSize = 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) void __fastcall exception_call_stack(void *instr, STACK_FRAME *stackFrame)
{ {
STACK_FRAME *oldStackFrame; STACK_FRAME *oldStackFrame;
char szModuleName[MAX_PATH];
int sectionNumber, sectionOffset;
log_printf("Call stack:\r\nAddress Frame Logical addr Module\r\n"); log_printf("Call stack:\r\nAddress Frame Logical addr Module\r\n");
do { do {
char szModuleName[MAX_PATH];
int sectionNumber, sectionOffset;
exception_unknown_module(instr, szModuleName, MAX_PATH, &sectionNumber, &sectionOffset); exception_unknown_module(instr, szModuleName, MAX_PATH, &sectionNumber, &sectionOffset);
log_printf("%08X %08X %04X:%08X %s\r\n", instr, stackFrame, sectionNumber, sectionOffset, szModuleName); 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) char *__fastcall exception_get_error_type(DWORD dwMessageId, LPSTR lpString1, DWORD nSize)
{ {
const char *v4; // eax const char *v4; // eax
HMODULE ntdll;
switch (dwMessageId) { switch (dwMessageId) {
CASE_EXCEPTION(v4, STACK_OVERFLOW); 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, SINGLE_STEP);
CASE_EXCEPTION(v4, ACCESS_VIOLATION); CASE_EXCEPTION(v4, ACCESS_VIOLATION);
default: 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)) { if (!FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, ntdll, dwMessageId, 0, lpString1, nSize, NULL)) {
v4 = "*unknown*"; v4 = "*unknown*";
} }

4
Source/gamemenu.cpp

@ -85,7 +85,9 @@ void __cdecl gamemenu_handle_previous()
void __cdecl gamemenu_new_game() 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]._pmode = PM_QUIT;
plr[i]._pInvincible = TRUE; plr[i]._pInvincible = TRUE;
} }

13
Source/init.cpp

@ -3,7 +3,7 @@
#include "../types.h" #include "../types.h"
_SNETVERSIONDATA fileinfo; _SNETVERSIONDATA fileinfo;
int init_cpp_init_value; // weak static float init_cpp_init_value = INFINITY;
int gbActive; // weak int gbActive; // weak
char diablo_exe_path[260]; char diablo_exe_path[260];
void *unused_mpq; void *unused_mpq;
@ -15,22 +15,11 @@ void *patch_rt_mpq;
int killed_mom_parent; // weak int killed_mom_parent; // weak
BOOLEAN screensaver_enabled_prev; BOOLEAN screensaver_enabled_prev;
const int init_inf = 0x7F800000; // weak
/* data */ /* data */
char gszVersionNumber[260] = "internal version unknown"; char gszVersionNumber[260] = "internal version unknown";
char gszProductName[260] = "Diablo v1.09"; 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) void __fastcall init_cleanup(BOOLEAN show_cursor)
{ {
int v1; // edi int v1; // edi

1
Source/init.h

@ -3,7 +3,6 @@
#define __INIT_H__ #define __INIT_H__
extern _SNETVERSIONDATA fileinfo; extern _SNETVERSIONDATA fileinfo;
extern int init_cpp_init_value; // weak
extern int gbActive; // weak extern int gbActive; // weak
extern char diablo_exe_path[260]; extern char diablo_exe_path[260];
extern void *unused_mpq; extern void *unused_mpq;

11
Source/interfac.cpp

@ -3,22 +3,13 @@
#include "../types.h" #include "../types.h"
void *sgpBackCel; void *sgpBackCel;
float interfac_cpp_init_value; static float interfac_cpp_init_value = INFINITY;
int sgdwProgress; int sgdwProgress;
int progress_id; // idb int progress_id; // idb
const int interfac_inf = 0x7F800000; // weak
const unsigned char progress_bar_colours[3] = { 138u, 43u, 254u }; const unsigned char progress_bar_colours[3] = { 138u, 43u, 254u };
const int progress_bar_screen_pos[3][2] = { { 53, 37 }, { 53, 421 }, { 53, 37 } }; 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() void __cdecl interface_msg_pump()
{ {
MSG Msg; // [esp+8h] [ebp-1Ch] MSG Msg; // [esp+8h] [ebp-1Ch]

1
Source/interfac.h

@ -3,7 +3,6 @@
#define __INTERFAC_H__ #define __INTERFAC_H__
extern void *sgpBackCel; extern void *sgpBackCel;
extern float interfac_cpp_init_value;
extern int sgdwProgress; extern int sgdwProgress;
extern int progress_id; // idb extern int progress_id; // idb

95
Source/inv.cpp

@ -148,17 +148,18 @@ void __fastcall InvDrawSlotBack(int X, int Y, int W, int H)
void __cdecl DrawInv() void __cdecl DrawInv()
{ {
BOOL invtest[40]; BOOL invtest[40];
int frame, frame_width, colour, screen_x, screen_y, i, j, ii;
CelDecodeOnly(384, 511, pInvCels, 1, 320); CelDecodeOnly(384, 511, pInvCels, 1, 320);
if (plr[myplr].InvBody[INVLOC_HEAD]._itype != ITYPE_NONE) { if (plr[myplr].InvBody[INVLOC_HEAD]._itype != ITYPE_NONE) {
InvDrawSlotBack(517, 219, 2 * INV_SLOT_SIZE_PX, 2 * INV_SLOT_SIZE_PX); InvDrawSlotBack(517, 219, 2 * INV_SLOT_SIZE_PX, 2 * INV_SLOT_SIZE_PX);
int frame = plr[myplr].InvBody[INVLOC_HEAD]._iCurs + 12; frame = plr[myplr].InvBody[INVLOC_HEAD]._iCurs + 12;
int frame_width = InvItemWidth[frame]; frame_width = InvItemWidth[frame];
if (pcursinvitem == INVITEM_HEAD) { if (pcursinvitem == INVITEM_HEAD) {
int colour = ICOL_WHITE; colour = ICOL_WHITE;
if (plr[myplr].InvBody[INVLOC_HEAD]._iMagical != ITEM_QUALITY_NORMAL) { if (plr[myplr].InvBody[INVLOC_HEAD]._iMagical != ITEM_QUALITY_NORMAL) {
colour = ICOL_BLUE; colour = ICOL_BLUE;
} }
@ -178,11 +179,11 @@ void __cdecl DrawInv()
if (plr[myplr].InvBody[INVLOC_RING_LEFT]._itype != ITYPE_NONE) { if (plr[myplr].InvBody[INVLOC_RING_LEFT]._itype != ITYPE_NONE) {
InvDrawSlotBack(432, 365, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); InvDrawSlotBack(432, 365, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX);
int frame = plr[myplr].InvBody[INVLOC_RING_LEFT]._iCurs + 12; frame = plr[myplr].InvBody[INVLOC_RING_LEFT]._iCurs + 12;
int frame_width = InvItemWidth[frame]; frame_width = InvItemWidth[frame];
if (pcursinvitem == INVITEM_RING_LEFT) { if (pcursinvitem == INVITEM_RING_LEFT) {
int colour = ICOL_WHITE; colour = ICOL_WHITE;
if (plr[myplr].InvBody[INVLOC_RING_LEFT]._iMagical != ITEM_QUALITY_NORMAL) { if (plr[myplr].InvBody[INVLOC_RING_LEFT]._iMagical != ITEM_QUALITY_NORMAL) {
colour = ICOL_BLUE; colour = ICOL_BLUE;
} }
@ -202,11 +203,11 @@ void __cdecl DrawInv()
if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._itype != ITYPE_NONE) { if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._itype != ITYPE_NONE) {
InvDrawSlotBack(633, 365, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); InvDrawSlotBack(633, 365, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX);
int frame = plr[myplr].InvBody[INVLOC_RING_RIGHT]._iCurs + 12; frame = plr[myplr].InvBody[INVLOC_RING_RIGHT]._iCurs + 12;
int frame_width = InvItemWidth[frame]; frame_width = InvItemWidth[frame];
if (pcursinvitem == INVITEM_RING_RIGHT) { if (pcursinvitem == INVITEM_RING_RIGHT) {
int colour = ICOL_WHITE; colour = ICOL_WHITE;
if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._iMagical != ITEM_QUALITY_NORMAL) { if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._iMagical != ITEM_QUALITY_NORMAL) {
colour = ICOL_BLUE; colour = ICOL_BLUE;
} }
@ -226,11 +227,11 @@ void __cdecl DrawInv()
if (plr[myplr].InvBody[INVLOC_AMULET]._itype != ITYPE_NONE) { if (plr[myplr].InvBody[INVLOC_AMULET]._itype != ITYPE_NONE) {
InvDrawSlotBack(589, 220, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); InvDrawSlotBack(589, 220, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX);
int frame = plr[myplr].InvBody[INVLOC_AMULET]._iCurs + 12; frame = plr[myplr].InvBody[INVLOC_AMULET]._iCurs + 12;
int frame_width = InvItemWidth[frame]; frame_width = InvItemWidth[frame];
if (pcursinvitem == INVITEM_AMULET) { if (pcursinvitem == INVITEM_AMULET) {
int colour = ICOL_WHITE; colour = ICOL_WHITE;
if (plr[myplr].InvBody[INVLOC_AMULET]._iMagical != ITEM_QUALITY_NORMAL) { if (plr[myplr].InvBody[INVLOC_AMULET]._iMagical != ITEM_QUALITY_NORMAL) {
colour = ICOL_BLUE; colour = ICOL_BLUE;
} }
@ -250,14 +251,14 @@ void __cdecl DrawInv()
if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_NONE) { if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_NONE) {
InvDrawSlotBack(401, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); InvDrawSlotBack(401, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX);
int frame = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCurs + 12; frame = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCurs + 12;
int frame_width = InvItemWidth[frame]; frame_width = InvItemWidth[frame];
// calc item offsets for weapons smaller than 2x3 slots // calc item offsets for weapons smaller than 2x3 slots
int screen_x = frame_width == INV_SLOT_SIZE_PX ? 415 : 401; screen_x = frame_width == INV_SLOT_SIZE_PX ? 415 : 401;
int screen_y = InvItemHeight[frame] == (3 * INV_SLOT_SIZE_PX) ? 320 : 306; screen_y = InvItemHeight[frame] == (3 * INV_SLOT_SIZE_PX) ? 320 : 306;
if (pcursinvitem == INVITEM_HAND_LEFT) { if (pcursinvitem == INVITEM_HAND_LEFT) {
int colour = ICOL_WHITE; colour = ICOL_WHITE;
if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMagical != ITEM_QUALITY_NORMAL) { if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMagical != ITEM_QUALITY_NORMAL) {
colour = ICOL_BLUE; colour = ICOL_BLUE;
} }
@ -290,14 +291,14 @@ void __cdecl DrawInv()
if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_NONE) { if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_NONE) {
InvDrawSlotBack(631, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); InvDrawSlotBack(631, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX);
int frame = plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iCurs + 12; frame = plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iCurs + 12;
int frame_width = InvItemWidth[frame]; frame_width = InvItemWidth[frame];
// calc item offsets for weapons smaller than 2x3 slots // calc item offsets for weapons smaller than 2x3 slots
int screen_x = frame_width == INV_SLOT_SIZE_PX ? 645 : 633; screen_x = frame_width == INV_SLOT_SIZE_PX ? 645 : 633;
int screen_y = InvItemHeight[frame] == 3 * INV_SLOT_SIZE_PX ? 320 : 306; screen_y = InvItemHeight[frame] == 3 * INV_SLOT_SIZE_PX ? 320 : 306;
if (pcursinvitem == INVITEM_HAND_RIGHT) { if (pcursinvitem == INVITEM_HAND_RIGHT) {
int colour = ICOL_WHITE; colour = ICOL_WHITE;
if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iMagical != ITEM_QUALITY_NORMAL) { if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iMagical != ITEM_QUALITY_NORMAL) {
colour = ICOL_BLUE; colour = ICOL_BLUE;
} }
@ -317,11 +318,11 @@ void __cdecl DrawInv()
if (plr[myplr].InvBody[INVLOC_CHEST]._itype != ITYPE_NONE) { if (plr[myplr].InvBody[INVLOC_CHEST]._itype != ITYPE_NONE) {
InvDrawSlotBack(517, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX); InvDrawSlotBack(517, 320, 2 * INV_SLOT_SIZE_PX, 3 * INV_SLOT_SIZE_PX);
int frame = plr[myplr].InvBody[INVLOC_CHEST]._iCurs + 12; frame = plr[myplr].InvBody[INVLOC_CHEST]._iCurs + 12;
int frame_width = InvItemWidth[frame]; frame_width = InvItemWidth[frame];
if (pcursinvitem == INVITEM_CHEST) { if (pcursinvitem == INVITEM_CHEST) {
int colour = ICOL_WHITE; colour = ICOL_WHITE;
if (plr[myplr].InvBody[INVLOC_CHEST]._iMagical != ITEM_QUALITY_NORMAL) { if (plr[myplr].InvBody[INVLOC_CHEST]._iMagical != ITEM_QUALITY_NORMAL) {
colour = ICOL_BLUE; 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) { if (plr[myplr].InvGrid[i] != 0) {
InvDrawSlotBack( InvDrawSlotBack(
InvRect[i + SLOTXY_INV_FIRST].X + 64, 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 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; invtest[j] = TRUE;
int frame = plr[myplr].InvList[ii]._iCurs + 12; frame = plr[myplr].InvList[ii]._iCurs + 12;
int frame_width = InvItemWidth[frame]; frame_width = InvItemWidth[frame];
if (pcursinvitem == ii + INVITEM_INV_FIRST) { if (pcursinvitem == ii + INVITEM_INV_FIRST) {
int colour = ICOL_WHITE; colour = ICOL_WHITE;
if (plr[myplr].InvList[ii]._iMagical != ITEM_QUALITY_NORMAL) { if (plr[myplr].InvList[ii]._iMagical != ITEM_QUALITY_NORMAL) {
colour = ICOL_BLUE; colour = ICOL_BLUE;
} }
@ -1376,9 +1377,11 @@ LABEL_81:
void __fastcall CheckInvSwap(int pnum, BYTE bLoc, int idx, WORD wCI, int seed, BOOL bId) void __fastcall CheckInvSwap(int pnum, BYTE bLoc, int idx, WORD wCI, int seed, BOOL bId)
{ {
PlayerStruct *p;
RecreateItem(MAXITEMS, idx, wCI, seed, 0); RecreateItem(MAXITEMS, idx, wCI, seed, 0);
PlayerStruct *p = &plr[pnum]; p = &plr[pnum];
p->HoldItem = item[MAXITEMS]; p->HoldItem = item[MAXITEMS];
if (bId) { 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) 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) { if (plr[pnum]._pmode > PM_WALK3) {
return; return;
} }
@ -1409,8 +1417,7 @@ void __fastcall CheckInvCut(int pnum, int mx, int my)
dropGoldValue = 0; dropGoldValue = 0;
} }
int r; done = FALSE;
BOOL done = FALSE;
// TODO: this loop is compiled differently (via InvRect pointers) // TODO: this loop is compiled differently (via InvRect pointers)
for (r = 0; (DWORD)r < NUM_XY_SLOTS && !done; r++) { 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) { 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) { if (ii) {
int iv = ii; iv = ii;
if (ii <= 0) { if (ii <= 0) {
iv = -ii; 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) { if (plr[pnum].InvGrid[i] == iv || plr[pnum].InvGrid[i] == -iv) {
plr[pnum].InvGrid[i] = 0; 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) { if (plr[pnum]._pNumInv > 0 && plr[pnum]._pNumInv != iv) {
plr[pnum].InvList[iv] = plr[pnum].InvList[plr[pnum]._pNumInv]; 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) { if (plr[pnum].InvGrid[j] == plr[pnum]._pNumInv + 1) {
plr[pnum].InvGrid[j] = iv + 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) { if (r >= SLOTXY_BELT_FIRST) {
int offs = r - SLOTXY_BELT_FIRST; offs = r - SLOTXY_BELT_FIRST;
if (plr[pnum].SpdList[offs]._itype != ITYPE_NONE) { if (plr[pnum].SpdList[offs]._itype != ITYPE_NONE) {
plr[pnum].HoldItem = plr[pnum].SpdList[offs]; plr[pnum].HoldItem = plr[pnum].SpdList[offs];
plr[pnum].SpdList[offs]._itype = ITYPE_NONE; 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) void __fastcall inv_update_rem_item(int pnum, BYTE iv)
{ {
BOOL Loadgfx;
if (iv < NUM_INVLOC) { if (iv < NUM_INVLOC) {
plr[pnum].InvBody[iv]._itype = ITYPE_NONE; plr[pnum].InvBody[iv]._itype = ITYPE_NONE;
} }
BOOL Loadgfx = FALSE; Loadgfx = FALSE;
if (plr[pnum]._pmode != PM_DEATH) { if (plr[pnum]._pmode != PM_DEATH) {
Loadgfx = TRUE; Loadgfx = TRUE;
@ -1567,9 +1576,11 @@ void __fastcall inv_update_rem_item(int pnum, BYTE iv)
void __fastcall RemoveInvItem(int pnum, int iv) void __fastcall RemoveInvItem(int pnum, int iv)
{ {
int i, j;
iv++; 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) { if (plr[pnum].InvGrid[i] == iv || plr[pnum].InvGrid[i] == -iv) {
plr[pnum].InvGrid[i] = 0; 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) { if (plr[pnum]._pNumInv > 0 && plr[pnum]._pNumInv != iv) {
plr[pnum].InvList[iv] = plr[pnum].InvList[plr[pnum]._pNumInv]; 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) { if (plr[pnum].InvGrid[j] == plr[pnum]._pNumInv + 1) {
plr[pnum].InvGrid[j] = iv + 1; plr[pnum].InvGrid[j] = iv + 1;
} }

12
Source/items.cpp

@ -745,6 +745,8 @@ void __cdecl InitItems()
void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx) void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx)
{ {
int pvid, d;
int mind = 0; // min damage int mind = 0; // min damage
int maxd = 0; // max damage int maxd = 0; // max damage
int tac = 0; // accuracy int tac = 0; // accuracy
@ -866,7 +868,7 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx)
if (plr[p]._pLightRad != lrad && p == myplr) { if (plr[p]._pLightRad != lrad && p == myplr) {
ChangeLightRadius(plr[p]._plid, lrad); ChangeLightRadius(plr[p]._plid, lrad);
int pvid = plr[p]._pvid; pvid = plr[p]._pvid;
if (lrad >= 10) { if (lrad >= 10) {
ChangeVisionRadius(pvid, lrad); ChangeVisionRadius(pvid, lrad);
} else { } else {
@ -1032,7 +1034,7 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx)
LoadPlrGFX(p, PFILE_STAND); LoadPlrGFX(p, PFILE_STAND);
SetPlrAnims(p); SetPlrAnims(p);
int d = plr[p]._pdir; d = plr[p]._pdir;
// TODO: Add debug assert here ( plr[p]._pNAnim[d] != NULL ) // TODO: Add debug assert here ( plr[p]._pNAnim[d] != NULL )
plr[p]._pAnimData = plr[p]._pNAnim[d]; plr[p]._pAnimData = plr[p]._pNAnim[d];
@ -1061,15 +1063,17 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx)
void __fastcall CalcPlrScrolls(int p) void __fastcall CalcPlrScrolls(int p)
{ {
int i, j;
plr[p]._pScrlSpells = 0; 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]._itype != ITYPE_NONE && (plr[p].InvList[i]._iMiscId == IMISC_SCROLL || plr[p].InvList[i]._iMiscId == IMISC_SCROLLT)) {
if (plr[p].InvList[i]._iStatFlag) if (plr[p].InvList[i]._iStatFlag)
plr[p]._pScrlSpells |= (__int64)1 << (plr[p].InvList[i]._iSpell - 1); 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]._itype != ITYPE_NONE && (plr[p].SpdList[j]._iMiscId == IMISC_SCROLL || plr[p].SpdList[j]._iMiscId == IMISC_SCROLLT)) {
if (plr[p].SpdList[j]._iStatFlag) if (plr[p].SpdList[j]._iStatFlag)
plr[p]._pScrlSpells |= (__int64)1 << (plr[p].SpdList[j]._iSpell - 1); plr[p]._pScrlSpells |= (__int64)1 << (plr[p].SpdList[j]._iSpell - 1);

25
Source/loadsave.cpp

@ -9,11 +9,13 @@ void __fastcall LoadGame(BOOL firstflag)
int i, j; int i, j;
DWORD dwLen; DWORD dwLen;
char szName[MAX_PATH]; char szName[MAX_PATH];
BYTE *LoadBuff;
int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects;
FreeGameMem(); FreeGameMem();
pfile_remove_temp_files(); pfile_remove_temp_files();
pfile_get_game_name(szName); pfile_get_game_name(szName);
BYTE *LoadBuff = pfile_read(szName, &dwLen); LoadBuff = pfile_read(szName, &dwLen);
tbuff = LoadBuff; tbuff = LoadBuff;
if (ILoad() != 'RETL') if (ILoad() != 'RETL')
@ -23,14 +25,14 @@ void __fastcall LoadGame(BOOL firstflag)
setlvlnum = WLoad(); setlvlnum = WLoad();
currlevel = WLoad(); currlevel = WLoad();
leveltype = WLoad(); leveltype = WLoad();
int _ViewX = WLoad(); _ViewX = WLoad();
int _ViewY = WLoad(); _ViewY = WLoad();
invflag = OLoad(); invflag = OLoad();
chrflag = OLoad(); chrflag = OLoad();
int _nummonsters = WLoad(); _nummonsters = WLoad();
int _numitems = WLoad(); _numitems = WLoad();
int _nummissiles = WLoad(); _nummissiles = WLoad();
int _nobjects = WLoad(); _nobjects = WLoad();
for (i = 0; i < NUMLEVELS; i++) { for (i = 0; i < NUMLEVELS; i++) {
glSeedTbl[i] = ILoad(); glSeedTbl[i] = ILoad();
@ -515,12 +517,14 @@ void __cdecl SaveLevel()
{ {
int i, j; int i, j;
char szName[MAX_PATH]; char szName[MAX_PATH];
int dwLen;
unsigned char *SaveBuff;
if (!currlevel) if (!currlevel)
glSeedTbl[0] = GetRndSeed(); glSeedTbl[0] = GetRndSeed();
int dwLen = codec_get_encoded_len(FILEBUFF); dwLen = codec_get_encoded_len(FILEBUFF);
unsigned char *SaveBuff = DiabloAllocPtr(dwLen); SaveBuff = DiabloAllocPtr(dwLen);
tbuff = SaveBuff; tbuff = SaveBuff;
if (leveltype) { if (leveltype) {
@ -607,9 +611,10 @@ void __cdecl LoadLevel()
int i, j; int i, j;
DWORD dwLen; DWORD dwLen;
char szName[MAX_PATH]; char szName[MAX_PATH];
BYTE *LoadBuff;
GetPermLevelNames(szName); GetPermLevelNames(szName);
BYTE *LoadBuff = pfile_read(szName, &dwLen); LoadBuff = pfile_read(szName, &dwLen);
tbuff = LoadBuff; tbuff = LoadBuff;
if (leveltype) { if (leveltype) {

13
Source/logging.cpp

@ -2,29 +2,18 @@
#include "../types.h" #include "../types.h"
int log_cpp_init_value; // weak static float log_cpp_init_value = INFINITY;
static CRITICAL_SECTION sgMemCrit; static CRITICAL_SECTION sgMemCrit;
CHAR FileName[260]; // idb CHAR FileName[260]; // idb
char log_buffer[388]; char log_buffer[388];
LPCVOID lpAddress; // idb LPCVOID lpAddress; // idb
DWORD nNumberOfBytesToWrite; // idb DWORD nNumberOfBytesToWrite; // idb
const int log_inf = 0x7F800000; // weak
/* data */ /* data */
int log_not_created = 1; // weak int log_not_created = 1; // weak
HANDLE log_file = (HANDLE)0xFFFFFFFF; // idb 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 { struct log_cpp_init_2 {
log_cpp_init_2() log_cpp_init_2()
{ {

1
Source/logging.h

@ -2,7 +2,6 @@
#ifndef __LOGGING_H__ #ifndef __LOGGING_H__
#define __LOGGING_H__ #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 char log_buffer[388];
extern LPCVOID lpAddress; // idb extern LPCVOID lpAddress; // idb

4
Source/mainmenu.cpp

@ -130,12 +130,14 @@ BOOL __cdecl mainmenu_single_player()
BOOL __fastcall mainmenu_init_menu(int type) BOOL __fastcall mainmenu_init_menu(int type)
{ {
BOOL success;
if (type == 4) if (type == 4)
return TRUE; return TRUE;
music_stop(); music_stop();
BOOL success = StartGame(type != 2, type != 3); success = StartGame(type != 2, type != 3);
if (success) if (success)
mainmenu_refresh_music(); mainmenu_refresh_music();

2
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] int v15; // [esp+10h] [ebp-Ch]
signed int v16; // [esp+14h] [ebp-8h] signed int v16; // [esp+14h] [ebp-8h]
signed int arglist; // [esp+18h] [ebp-4h] signed int arglist; // [esp+18h] [ebp-4h]
BOOL ret;
v16 = 0; v16 = 0;
arglist = m; arglist = m;
@ -850,7 +851,6 @@ BOOL __fastcall MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, i
if (v10 > 95) if (v10 > 95)
v10 = 95; v10 = 95;
//_LOBYTE(v11) = CheckMonsterHit(arglist, (unsigned char *)&t); //_LOBYTE(v11) = CheckMonsterHit(arglist, (unsigned char *)&t);
BOOL ret;
if (CheckMonsterHit(arglist, &ret)) if (CheckMonsterHit(arglist, &ret))
return ret; return ret;
#ifdef _DEBUG #ifdef _DEBUG

12
Source/monster.cpp

@ -5,7 +5,7 @@
// Tracks which missile files are already loaded // Tracks which missile files are already loaded
int MissileFileFlag; int MissileFileFlag;
int monster_cpp_init_value; // weak static float monster_cpp_init_value = INFINITY;
int monstkills[MAXMONSTERS]; int monstkills[MAXMONSTERS];
int monstactive[MAXMONSTERS]; int monstactive[MAXMONSTERS];
int nummonsters; int nummonsters;
@ -18,7 +18,6 @@ int monstimgtot; // weak
int uniquetrans; int uniquetrans;
int nummtypes; int nummtypes;
const int monster_inf = 0x7F800000; // weak
const char plr2monst[9] = { 0, 5, 3, 7, 1, 4, 6, 0, 2 }; 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 }; const unsigned char counsmiss[4] = { MIS_FIREBOLT, MIS_CBOLT, MIS_LIGHTCTRL, MIS_FIREBALL };
@ -349,15 +348,6 @@ void(__fastcall *AiProc[])(int i) = {
&MAI_Warlord &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) void __fastcall InitMonsterTRN(int monst, BOOL special)
{ {
BYTE *f; BYTE *f;

4
Source/monster.h

@ -2,8 +2,7 @@
#ifndef __MONSTER_H__ #ifndef __MONSTER_H__
#define __MONSTER_H__ #define __MONSTER_H__
extern int MissileFileFlag; // weak extern int MissileFileFlag; // weak
extern int monster_cpp_init_value; // weak
extern int monstkills[MAXMONSTERS]; extern int monstkills[MAXMONSTERS];
extern int monstactive[MAXMONSTERS]; extern int monstactive[MAXMONSTERS];
extern int nummonsters; extern int nummonsters;
@ -165,7 +164,6 @@ void __fastcall decode_enemy(int m, int enemy);
/* rdata */ /* rdata */
extern const int monster_inf; // weak
extern const char plr2monst[9]; extern const char plr2monst[9];
extern const unsigned char counsmiss[4]; extern const unsigned char counsmiss[4];

19
Source/movie.cpp

@ -2,28 +2,20 @@
#include "../types.h" #include "../types.h"
int movie_cpp_init_value; // weak static float movie_cpp_init_value = INFINITY;
BYTE movie_playing; BYTE movie_playing;
BOOL loop_movie; 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) void __fastcall play_movie(char *pszMovie, BOOL user_can_close)
{ {
WNDPROC saveProc;
void *video_stream;
if (!gbActive) { if (!gbActive) {
return; return;
} }
WNDPROC saveProc = SetWindowProc(MovieWndProc); saveProc = SetWindowProc(MovieWndProc);
InvalidateRect(ghMainWnd, 0, 0); InvalidateRect(ghMainWnd, 0, 0);
UpdateWindow(ghMainWnd); UpdateWindow(ghMainWnd);
movie_playing = TRUE; movie_playing = TRUE;
@ -31,7 +23,6 @@ void __fastcall play_movie(char *pszMovie, BOOL user_can_close)
sfx_stop(); sfx_stop();
effects_play_sound("Sfx\\Misc\\blank.wav"); effects_play_sound("Sfx\\Misc\\blank.wav");
void *video_stream;
SVidPlayBegin(pszMovie, 0, 0, 0, 0, loop_movie ? 0x100C0808 : 0x10280808, &video_stream); SVidPlayBegin(pszMovie, 0, 0, 0, 0, loop_movie ? 0x100C0808 : 0x10280808, &video_stream);
if (video_stream) { if (video_stream) {
MSG Msg; MSG Msg;

3
Source/movie.h

@ -2,7 +2,6 @@
#ifndef __MOVIE_H__ #ifndef __MOVIE_H__
#define __MOVIE_H__ #define __MOVIE_H__
extern int movie_cpp_init_value; // weak
extern BYTE movie_playing; extern BYTE movie_playing;
extern BOOL loop_movie; extern BOOL loop_movie;
@ -12,6 +11,4 @@ LRESULT __stdcall MovieWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam
/* rdata */ /* rdata */
extern const int movie_inf; // weak
#endif /* __MOVIE_H__ */ #endif /* __MOVIE_H__ */

15
Source/mpqapi.cpp

@ -2,31 +2,20 @@
#include "../types.h" #include "../types.h"
int mpqapi_cpp_init_value; // weak static float mpqapi_cpp_init_value = INFINITY;
int sgdwMpqOffset; // idb int sgdwMpqOffset; // idb
char mpq_buf[4096]; char mpq_buf[4096];
_HASHENTRY *sgpHashTbl; _HASHENTRY *sgpHashTbl;
BOOLEAN save_archive_modified; // weak BOOLEAN save_archive_modified; // weak
_BLOCKENTRY *sgpBlockTbl; _BLOCKENTRY *sgpBlockTbl;
BOOLEAN save_archive_open; // weak BOOLEAN save_archive_open; // weak
const int mpqapi_inf = 0x7F800000; // weak
//note: 32872 = 32768 + 104 (sizeof(_FILEHEADER)) //note: 32872 = 32768 + 104 (sizeof(_FILEHEADER))
/* data */ /* data */
HANDLE sghArchive = (HANDLE)0xFFFFFFFF; // idb 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) BOOLEAN __fastcall mpqapi_set_hidden(const char *pszArchive, BOOLEAN hidden)
{ {
const char *v2; // edi const char *v2; // edi

3
Source/mpqapi.h

@ -2,7 +2,6 @@
#ifndef __MPQAPI_H__ #ifndef __MPQAPI_H__
#define __MPQAPI_H__ #define __MPQAPI_H__
extern int mpqapi_cpp_init_value; // weak
extern int sgdwMpqOffset; // idb extern int sgdwMpqOffset; // idb
extern char mpq_buf[4096]; extern char mpq_buf[4096];
extern _HASHENTRY *sgpHashTbl; extern _HASHENTRY *sgpHashTbl;
@ -42,8 +41,6 @@ BOOLEAN __cdecl mpqapi_can_seek();
/* rdata */ /* rdata */
extern const int mpqapi_inf; // weak
/* data */ /* data */
extern HANDLE sghArchive; // idb extern HANDLE sghArchive; // idb

13
Source/msgcmd.cpp

@ -4,21 +4,10 @@
/* TODO: decompile and fix, commands are NOT deleted properly */ /* 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; ChatCmd sgChat_Cmd;
int sgdwMsgCmdTimer; 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 { struct msgcmd_cpp_init_2 {
msgcmd_cpp_init_2() msgcmd_cpp_init_2()
{ {

3
Source/msgcmd.h

@ -2,7 +2,6 @@
#ifndef __MSGCMD_H__ #ifndef __MSGCMD_H__
#define __MSGCMD_H__ #define __MSGCMD_H__
extern int msgcmd_cpp_init_value; // weak
extern ChatCmd sgChat_Cmd; extern ChatCmd sgChat_Cmd;
extern int sgdwMsgCmdTimer; extern int sgdwMsgCmdTimer;
@ -26,6 +25,4 @@ void __fastcall msgcmd_cleanup_extern_msg(ServerCommand **extern_msgs);
/* rdata */ /* rdata */
extern const int msgcmd_inf; // weak
#endif /* __MSGCMD_H__ */ #endif /* __MSGCMD_H__ */

12
Source/multi.cpp

@ -9,7 +9,7 @@ short sgwPackPlrOffsetTbl[MAX_PLRS];
PkPlayerStruct netplr[MAX_PLRS]; PkPlayerStruct netplr[MAX_PLRS];
char sgbPlayerTurnBitTbl[MAX_PLRS]; char sgbPlayerTurnBitTbl[MAX_PLRS];
char sgbPlayerLeftGameTbl[MAX_PLRS]; char sgbPlayerLeftGameTbl[MAX_PLRS];
int multi_cpp_init_value; // weak static float multi_cpp_init_value = INFINITY;
int sgbSentThisCycle; // idb int sgbSentThisCycle; // idb
int dword_678628; // weak int dword_678628; // weak
BYTE gbActivePlayers; // weak BYTE gbActivePlayers; // weak
@ -28,22 +28,12 @@ BYTE gbDeltaSender;
int sgbNetInited; // weak int sgbNetInited; // weak
int player_state[MAX_PLRS]; int player_state[MAX_PLRS];
const int multi_inf = 0x7F800000; // weak
const int event_types[3] = { const int event_types[3] = {
EVENT_TYPE_PLAYER_LEAVE_GAME, EVENT_TYPE_PLAYER_LEAVE_GAME,
EVENT_TYPE_PLAYER_CREATE_GAME, EVENT_TYPE_PLAYER_CREATE_GAME,
EVENT_TYPE_PLAYER_MESSAGE 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) void __fastcall multi_msg_add(BYTE *a1, unsigned char a2)
{ {
if (a1) { if (a1) {

1
Source/multi.h

@ -9,7 +9,6 @@ extern short sgwPackPlrOffsetTbl[MAX_PLRS];
extern PkPlayerStruct netplr[MAX_PLRS]; extern PkPlayerStruct netplr[MAX_PLRS];
extern char sgbPlayerTurnBitTbl[MAX_PLRS]; extern char sgbPlayerTurnBitTbl[MAX_PLRS];
extern char sgbPlayerLeftGameTbl[MAX_PLRS]; extern char sgbPlayerLeftGameTbl[MAX_PLRS];
extern int multi_cpp_init_value; // weak
extern int sgbSentThisCycle; // idb extern int sgbSentThisCycle; // idb
extern int dword_678628; // weak extern int dword_678628; // weak
extern BYTE gbActivePlayers; extern BYTE gbActivePlayers;

15
Source/nthread.cpp

@ -2,8 +2,8 @@
#include "../types.h" #include "../types.h"
int nthread_cpp_init_value; // weak static float nthread_cpp_init_value = INFINITY;
char byte_679704; // weak char byte_679704; // weak
int gdwMsgLenTbl[4]; int gdwMsgLenTbl[4];
static CRITICAL_SECTION sgMemCrit; static CRITICAL_SECTION sgMemCrit;
int gdwDeltaBytesSec; // weak int gdwDeltaBytesSec; // weak
@ -20,20 +20,9 @@ int gdwLargestMsgSize; // weak
int gdwNormalMsgSize; // weak int gdwNormalMsgSize; // weak
int last_tick; // weak int last_tick; // weak
const int nthread_inf = 0x7F800000; // weak
/* data */ /* data */
static HANDLE sghThread = (HANDLE)0xFFFFFFFF; // idb 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 { struct nthread_cpp_init_2 {
nthread_cpp_init_2() nthread_cpp_init_2()
{ {

3
Source/nthread.h

@ -2,7 +2,6 @@
#ifndef __NTHREAD_H__ #ifndef __NTHREAD_H__
#define __NTHREAD_H__ #define __NTHREAD_H__
extern int nthread_cpp_init_value; // weak
extern char byte_679704; // weak extern char byte_679704; // weak
extern int gdwMsgLenTbl[4]; extern int gdwMsgLenTbl[4];
extern int gdwDeltaBytesSec; // weak extern int gdwDeltaBytesSec; // weak
@ -34,6 +33,4 @@ BOOL __fastcall nthread_has_500ms_passed(BOOL unused);
/* rdata */ /* rdata */
extern const int nthread_inf; // weak
#endif /* __NTHREAD_H__ */ #endif /* __NTHREAD_H__ */

13
Source/pack.cpp

@ -2,18 +2,7 @@
#include "../types.h" #include "../types.h"
int pack_cpp_init_value; // weak static float pack_cpp_init_value = INFINITY;
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;
void __fastcall PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield) void __fastcall PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield)
{ {

4
Source/pack.h

@ -2,8 +2,6 @@
#ifndef __PACK_H__ #ifndef __PACK_H__
#define __PACK_H__ #define __PACK_H__
extern int pack_cpp_init_value; // weak
void __cdecl pack_cpp_init(); void __cdecl pack_cpp_init();
void __fastcall PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield); void __fastcall PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield);
void __fastcall PackItem(PkItemStruct *id, ItemStruct *is); void __fastcall PackItem(PkItemStruct *id, ItemStruct *is);
@ -13,6 +11,4 @@ void __fastcall UnPackItem(PkItemStruct *is, ItemStruct *id);
/* rdata */ /* rdata */
extern const int pack_inf; // weak
#endif /* __PACK_H__ */ #endif /* __PACK_H__ */

13
Source/palette.cpp

@ -3,28 +3,17 @@
#include "../types.h" #include "../types.h"
PALETTEENTRY logical_palette[256]; PALETTEENTRY logical_palette[256];
int palette_cpp_init_value; // weak static float palette_cpp_init_value = INFINITY;
PALETTEENTRY system_palette[256]; PALETTEENTRY system_palette[256];
PALETTEENTRY orig_palette[256]; PALETTEENTRY orig_palette[256];
UINT gdwPalEntries; UINT gdwPalEntries;
const int palette_inf = 0x7F800000; // weak
/* data */ /* data */
int gamma_correction = 100; // idb int gamma_correction = 100; // idb
BOOL color_cycling_enabled = TRUE; BOOL color_cycling_enabled = TRUE;
BOOLEAN sgbFadedIn = 1; 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() void __cdecl SaveGamma()
{ {
SRegSaveValue("Diablo", "Gamma Correction", 0, gamma_correction); SRegSaveValue("Diablo", "Gamma Correction", 0, gamma_correction);

3
Source/palette.h

@ -3,7 +3,6 @@
#define __PALETTE_H__ #define __PALETTE_H__
extern PALETTEENTRY logical_palette[256]; extern PALETTEENTRY logical_palette[256];
extern int palette_cpp_init_value; // weak
extern PALETTEENTRY system_palette[256]; extern PALETTEENTRY system_palette[256];
extern PALETTEENTRY orig_palette[256]; extern PALETTEENTRY orig_palette[256];
extern UINT gdwPalEntries; extern UINT gdwPalEntries;
@ -32,8 +31,6 @@ void __fastcall palette_set_color_cycling(BOOLEAN enabled);
/* rdata */ /* rdata */
extern const int palette_inf; // weak
/* data */ /* data */
extern int gamma_correction; // idb extern int gamma_correction; // idb

4
Source/path.cpp

@ -362,10 +362,12 @@ PATHNODE *__cdecl path_pop_active_step()
* none are available */ * none are available */
PATHNODE *__cdecl path_new_step() PATHNODE *__cdecl path_new_step()
{ {
PATHNODE *new_node;
if (gdwCurNodes == MAXPATHNODES) if (gdwCurNodes == MAXPATHNODES)
return NULL; return NULL;
PATHNODE *new_node = &path_nodes[gdwCurNodes]; new_node = &path_nodes[gdwCurNodes];
gdwCurNodes++; gdwCurNodes++;
memset(new_node, 0, sizeof(PATHNODE)); memset(new_node, 0, sizeof(PATHNODE));
return new_node; return new_node;

14
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) BOOL __fastcall pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack)
{ {
HANDLE file; HANDLE file;
BOOL decoded, ret;
DWORD dwlen, nSize;
unsigned char *buf;
if (!SFileOpenFileEx(archive, "hero", 0, &file)) if (!SFileOpenFileEx(archive, "hero", 0, &file))
return FALSE; return FALSE;
else { else {
DWORD dwlen; ret = FALSE;
BOOL ret = FALSE;
char password[16] = PASSWORD_SINGLE; char password[16] = PASSWORD_SINGLE;
DWORD nSize = 16; nSize = 16;
if (gbMaxPlayers > 1) if (gbMaxPlayers > 1)
strcpy(password, PASSWORD_MULTI); strcpy(password, PASSWORD_MULTI);
@ -330,9 +332,9 @@ BOOL __fastcall pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack)
dwlen = SFileGetFileSize(file, NULL); dwlen = SFileGetFileSize(file, NULL);
if (dwlen) { if (dwlen) {
DWORD read; DWORD read;
unsigned char *buf = DiabloAllocPtr(dwlen); buf = DiabloAllocPtr(dwlen);
if (SFileReadFile(file, buf, dwlen, &read, NULL)) { if (SFileReadFile(file, buf, dwlen, &read, NULL)) {
BOOL decoded = TRUE; decoded = TRUE;
read = codec_decode(buf, dwlen, password); read = codec_decode(buf, dwlen, password);
if (!read && gbMaxPlayers > 1) { if (!read && gbMaxPlayers > 1) {
GetComputerName(password, &nSize); GetComputerName(password, &nSize);
@ -422,7 +424,7 @@ BOOL __stdcall pfile_ui_save_create(_uiheroinfo *heroinfo)
break; break;
} }
if (save_num == MAX_CHARACTERS) if (save_num == MAX_CHARACTERS)
return false; return FALSE;
} }
if (!pfile_open_archive(FALSE, save_num)) if (!pfile_open_archive(FALSE, save_num))
return FALSE; return FALSE;

11
Source/player.cpp

@ -5,7 +5,7 @@
int plr_lframe_size; int plr_lframe_size;
int plr_wframe_size; int plr_wframe_size;
UCHAR plr_gfx_flag = 0; UCHAR plr_gfx_flag = 0;
int player_cpp_init_value; static float player_cpp_init_value = INFINITY;
int plr_aframe_size; int plr_aframe_size;
int myplr; int myplr;
PlayerStruct plr[MAX_PLRS]; PlayerStruct plr[MAX_PLRS];
@ -19,7 +19,6 @@ int plr_sframe_size;
int deathdelay; int deathdelay;
int plr_dframe_size; int plr_dframe_size;
const int player_inf = 0x7F800000; // weak
const char ArmourChar[4] = { 'L', 'M', 'H', 0 }; const char ArmourChar[4] = { 'L', 'M', 'H', 0 };
const char WepChar[10] = { 'N', 'U', 'S', 'D', 'B', 'A', 'M', 'H', 'T', 0 }; const char WepChar[10] = { 'N', 'U', 'S', 'D', 'B', 'A', 'M', 'H', 'T', 0 };
const char CharChar[4] = { 'W', 'R', 'S', 0 }; const char CharChar[4] = { 'W', 'R', 'S', 0 };
@ -108,14 +107,6 @@ int ExpLvlsTbl[MAXCHARLEVEL] = {
char *ClassStrTbl[3] = { "Warrior", "Rogue", "Sorceror" }; char *ClassStrTbl[3] = { "Warrior", "Rogue", "Sorceror" };
unsigned char fix[9] = { 0u, 0u, 3u, 3u, 3u, 6u, 6u, 6u, 8u }; /* PM_ChangeLightOff local type */ 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) void __fastcall SetPlayerGPtrs(UCHAR *pData, UCHAR **pAnim)
{ {

2
Source/player.h

@ -5,7 +5,6 @@
extern int plr_lframe_size; // idb extern int plr_lframe_size; // idb
extern int plr_wframe_size; // idb extern int plr_wframe_size; // idb
extern UCHAR plr_gfx_flag; extern UCHAR plr_gfx_flag;
extern int player_cpp_init_value; // weak
extern int plr_aframe_size; // idb extern int plr_aframe_size; // idb
extern int myplr; extern int myplr;
extern PlayerStruct plr[MAX_PLRS]; extern PlayerStruct plr[MAX_PLRS];
@ -113,7 +112,6 @@ void __cdecl PlayDungMsgs();
/* rdata */ /* rdata */
extern const int player_inf;
extern const char ArmourChar[4]; extern const char ArmourChar[4];
extern const char WepChar[10]; extern const char WepChar[10];
extern const char CharChar[4]; extern const char CharChar[4];

Loading…
Cancel
Save