From 024d99fc9e2eee86870ce19c4ada65484123111b Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 29 Dec 2018 21:15:33 +0100 Subject: [PATCH] C compatability from s (#521) --- Source/scrollrt.cpp | 13 +---------- Source/scrollrt.h | 3 --- Source/sha.cpp | 13 +++++++---- Source/sound.cpp | 57 +++++++++++++++++++++++---------------------- Source/sound.h | 3 --- Source/spells.cpp | 33 +++++++++++++++----------- 6 files changed, 58 insertions(+), 64 deletions(-) diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 41200ca13..521b4bcb7 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -4,7 +4,7 @@ int light_table_index; // weak int screen_y_times_768[1024]; -int scrollrt_cpp_init_value; // weak +static float scrollrt_cpp_init_value = INFINITY; unsigned int sgdwCursWdtOld; // idb int sgdwCursX; // idb int sgdwCursY; // idb @@ -23,8 +23,6 @@ char sgSaveBack[8192]; int draw_monster_num; // weak int sgdwCursHgtOld; // idb -const int scrollrt_inf = 0x7F800000; // weak - /* data */ /* used in 1.00 debug */ @@ -64,15 +62,6 @@ char *szPlrModeAssert[12] = { "quitting" }; -struct scrollrt_cpp_init { - scrollrt_cpp_init() - { - scrollrt_cpp_init_value = scrollrt_inf; - } -} _scrollrt_cpp_init; -// 47F238: using guessed type int scrollrt_inf; -// 69CEFC: using guessed type int scrollrt_cpp_init_value; - void __cdecl ClearCursor() // CODE_FIX: this was supposed to be in cursor.cpp { sgdwCursWdt = 0; diff --git a/Source/scrollrt.h b/Source/scrollrt.h index 88d6d99d7..f3f7d8ce5 100644 --- a/Source/scrollrt.h +++ b/Source/scrollrt.h @@ -4,7 +4,6 @@ extern int light_table_index; // weak extern int screen_y_times_768[1024]; -extern int scrollrt_cpp_init_value; // weak extern unsigned int sgdwCursWdtOld; // idb extern int sgdwCursX; // idb extern int sgdwCursY; // idb @@ -63,8 +62,6 @@ void __cdecl DrawAndBlit(); /* rdata */ -extern const int scrollrt_inf; // weak - /* data */ /* used in 1.00 debug */ diff --git a/Source/sha.cpp b/Source/sha.cpp index 93927a98d..edcf595bb 100644 --- a/Source/sha.cpp +++ b/Source/sha.cpp @@ -11,9 +11,12 @@ void __cdecl SHA1Clear() void __fastcall SHA1Result(int n, char Message_Digest[SHA1HashSize]) { - DWORD *Message_Digest_Block = (DWORD *)Message_Digest; + DWORD *Message_Digest_Block; + int i; + + Message_Digest_Block = (DWORD *)Message_Digest; if (Message_Digest) { - for (int i = 0; i < 5; i++) { + for (i = 0; i < 5; i++) { *Message_Digest_Block = sgSHA1[n].state[i]; Message_Digest_Block++; } @@ -29,14 +32,16 @@ void __fastcall SHA1Calculate(int n, const char *data, char Message_Digest[SHA1H void __fastcall SHA1Input(SHA1Context *context, const char *message_array, int len) { - int count = context->count[0] + 8 * len; + int i, count; + + count = context->count[0] + 8 * len; if (count < context->count[0]) context->count[1]++; context->count[0] = count; context->count[1] += len >> 29; - for (int i = len; i >= 64; i -= 64) { + for (i = len; i >= 64; i -= 64) { memcpy(context->buffer, message_array, sizeof(context->buffer)); SHA1ProcessMessageBlock(context); message_array += 64; diff --git a/Source/sound.cpp b/Source/sound.cpp index 787274785..97f43e46d 100644 --- a/Source/sound.cpp +++ b/Source/sound.cpp @@ -2,7 +2,7 @@ #include "../types.h" -float sound_cpp_init_value; +static float sound_cpp_init_value = INFINITY; LPDIRECTSOUNDBUFFER DSBs[8]; LPDIRECTSOUND sglpDS; char gbSndInited; @@ -12,8 +12,6 @@ HMODULE hDsound_dll; HANDLE sgpMusicTrack; LPDIRECTSOUNDBUFFER sglpDSB; -const int sound_inf = 0x7F800000; // weak - /* data */ BYTE gbMusicOn = TRUE; @@ -35,19 +33,11 @@ char unk_volume[4][2] = { { 30, -31 } }; -struct sound_cpp_init { - sound_cpp_init() - { - sound_cpp_init_value = sound_inf; - } -} _sound_cpp_init; -// 47F24C: using guessed type int sound_inf; - void __fastcall snd_update(BOOL bStopAll) { - DWORD error_code; + DWORD error_code, i; - for (DWORD i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) { if (!DSBs[i]) continue; @@ -68,7 +58,7 @@ void __fastcall snd_stop_snd(TSnd *pSnd) BOOL __fastcall snd_playing(TSnd *pSnd) { - DWORD error_code; + DWORD error_code; // TODO should probably be HRESULT if (!pSnd) return FALSE; @@ -84,16 +74,20 @@ BOOL __fastcall snd_playing(TSnd *pSnd) void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan) { + LPDIRECTSOUNDBUFFER DSB; + DWORD tc; + HRESULT error_code; + if (!pSnd || !gbSoundOn) { return; } - LPDIRECTSOUNDBUFFER DSB = pSnd->DSB; + DSB = pSnd->DSB; if (!DSB) { return; } - DWORD tc = GetTickCount(); + tc = GetTickCount(); if (tc - pSnd->start_tc < 80) { pSnd->start_tc = GetTickCount(); return; @@ -116,7 +110,7 @@ void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan) DSB->SetPan(lPan); - HRESULT error_code = DSB->Play(0, 0, 0); + error_code = DSB->Play(0, 0, 0); if (error_code != DSERR_BUFFERLOST) { if (error_code != DS_OK) { DSErrMsg(error_code, 261, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); @@ -130,11 +124,13 @@ void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan) LPDIRECTSOUNDBUFFER __fastcall sound_dup_channel(LPDIRECTSOUNDBUFFER DSB) { + DWORD i; + if (!gbDupSounds) { return NULL; } - for (DWORD i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) { if (!DSBs[i]) { if (sglpDS->DuplicateSoundBuffer(DSB, &DSBs[i]) != DS_OK) { return NULL; @@ -149,14 +145,15 @@ LPDIRECTSOUNDBUFFER __fastcall sound_dup_channel(LPDIRECTSOUNDBUFFER DSB) BOOL __fastcall sound_file_reload(TSnd *sound_file, LPDIRECTSOUNDBUFFER DSB) { - if (DSB->Restore()) - return FALSE; - HANDLE file; LPVOID buf1, buf2; DWORD size1, size2; + BOOL rv; - BOOL rv = FALSE; + if (DSB->Restore()) + return FALSE; + + rv = FALSE; WOpenFile(sound_file->sound_path, &file, 0); WSetFilePointer(file, sound_file->chunk.dwOffset, 0, 0); @@ -174,12 +171,17 @@ BOOL __fastcall sound_file_reload(TSnd *sound_file, LPDIRECTSOUNDBUFFER DSB) TSnd *__fastcall sound_file_load(char *path) { + void *file, *wave_file; + TSnd *pSnd; + LPVOID buf1, buf2; + DWORD size1, size2; + HRESULT error_code; + if (!sglpDS) return NULL; - void *file, *wave_file; WOpenFile(path, &file, 0); - TSnd *pSnd = (TSnd *)DiabloAllocPtr(40); + pSnd = (TSnd *)DiabloAllocPtr(40); memset(pSnd, 0, sizeof(TSnd)); pSnd->sound_path = path; pSnd->start_tc = GetTickCount() - 81; @@ -190,9 +192,7 @@ TSnd *__fastcall sound_file_load(char *path) sound_CreateSoundBuffer(pSnd); - LPVOID buf1, buf2; - DWORD size1, size2; - HRESULT error_code = pSnd->DSB->Lock(0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0); + error_code = pSnd->DSB->Lock(0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0); if (error_code != DS_OK) DSErrMsg(error_code, 318, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); @@ -212,6 +212,7 @@ TSnd *__fastcall sound_file_load(char *path) void __fastcall sound_CreateSoundBuffer(TSnd *sound_file) { DSBUFFERDESC DSB; + HRESULT error_code; memset(&DSB, 0, sizeof(DSBUFFERDESC)); DSB.dwBufferBytes = sound_file->chunk.dwSize; @@ -219,7 +220,7 @@ void __fastcall sound_CreateSoundBuffer(TSnd *sound_file) DSB.dwSize = sizeof(DSBUFFERDESC); DSB.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_STATIC; - HRESULT error_code = sglpDS->CreateSoundBuffer(&DSB, &sound_file->DSB, NULL); + error_code = sglpDS->CreateSoundBuffer(&DSB, &sound_file->DSB, NULL); if (error_code != ERROR_SUCCESS) DSErrMsg(error_code, 282, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); } diff --git a/Source/sound.h b/Source/sound.h index 0d235f9f6..7a7761fa2 100644 --- a/Source/sound.h +++ b/Source/sound.h @@ -2,7 +2,6 @@ #ifndef __SOUND_H__ #define __SOUND_H__ -extern float sound_cpp_init_value; extern IDirectSoundBuffer *DSBs[8]; extern LPDIRECTSOUND sglpDS; extern char gbSndInited; @@ -36,8 +35,6 @@ int __fastcall sound_get_or_set_sound_volume(int volume); /* rdata */ -extern const int sound_inf; // weak - /* data */ extern BYTE gbMusicOn; diff --git a/Source/spells.cpp b/Source/spells.cpp index 363387bf7..b82dc7903 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -150,7 +150,7 @@ BOOL __fastcall CheckSpell(int id, int sn, BYTE st, BOOL manaonly) void __fastcall CastSpell(int id, int spl, int sx, int sy, int dx, int dy, BOOL caster, int spllvl) { - + int i; int dir; // missile direction // ugly switch, but generates the right code @@ -170,7 +170,7 @@ void __fastcall CastSpell(int id, int spl, int sx, int sy, int dx, int dy, BOOL break; } - for (int i = 0; spelldata[spl].sMissiles[i] != MIS_ARROW && i < 3; i++) { + for (i = 0; spelldata[spl].sMissiles[i] != MIS_ARROW && i < 3; i++) { AddMissile(sx, sy, dx, dy, dir, spelldata[spl].sMissiles[i], caster, id, 0, spllvl); } @@ -180,7 +180,7 @@ void __fastcall CastSpell(int id, int spl, int sx, int sy, int dx, int dy, BOOL if (spelldata[spl].sMissiles[0] == MIS_CBOLT) { UseMana(id, SPL_CBOLT); - for (int i = 0; i < (spllvl >> 1) + 3; i++) { + for (i = 0; i < (spllvl >> 1) + 3; i++) { AddMissile(sx, sy, dx, dy, dir, MIS_CBOLT, caster, id, 0, spllvl); } } @@ -190,6 +190,8 @@ void __fastcall CastSpell(int id, int spl, int sx, int sy, int dx, int dy, BOOL // rid: target player index void __fastcall DoResurrect(int pnum, int rid) { + int hp; + if ((char)rid != -1) { AddMissile(plr[rid].WorldX, plr[rid].WorldY, plr[rid].WorldX, plr[rid].WorldY, 0, MIS_RESURRECTBEAM, 0, pnum, 0, 0); } @@ -211,7 +213,7 @@ void __fastcall DoResurrect(int pnum, int rid) plr[rid]._pInvincible = 0; PlacePlayer(rid); - int hp = 640; + hp = 640; if (plr[rid]._pMaxHPBase < 640) { hp = plr[rid]._pMaxHPBase; } @@ -233,11 +235,12 @@ void __fastcall DoResurrect(int pnum, int rid) void __fastcall PlacePlayer(int pnum) { - int nx; - int ny; + int nx, ny, max, min, x, y; + DWORD i; + BOOL done; if (plr[pnum].plrlevel == currlevel) { - for (DWORD i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) { nx = plr[pnum].WorldX + plrxoff2[i]; ny = plr[pnum].WorldY + plryoff2[i]; @@ -247,13 +250,13 @@ void __fastcall PlacePlayer(int pnum) } if (!PosOkPlayer(pnum, nx, ny)) { - BOOL done = FALSE; + done = FALSE; - for (int max = 1, min = -1; min > -50 && !done; max++, min--) { - for (int y = min; y <= max && !done; y++) { + for (max = 1, min = -1; min > -50 && !done; max++, min--) { + for (y = min; y <= max && !done; y++) { ny = plr[pnum].WorldY + y; - for (int x = min; x <= max && !done; x++) { + for (x = min; x <= max && !done; x++) { nx = plr[pnum].WorldX + x; if (PosOkPlayer(pnum, nx, ny)) { @@ -278,18 +281,20 @@ void __fastcall PlacePlayer(int pnum) void __fastcall DoHealOther(int pnum, int rid) { + int i, j, hp; + if (pnum == myplr) { NewCursor(CURSOR_HAND); } if ((char)rid != -1 && (plr[rid]._pHitPoints >> 6) > 0) { - int hp = (random(57, 10) + 1) << 6; + hp = (random(57, 10) + 1) << 6; - for (int i = 0; i < plr[pnum]._pLevel; i++) { + for (i = 0; i < plr[pnum]._pLevel; i++) { hp += (random(57, 4) + 1) << 6; } - for (int j = 0; j < GetSpellLevel(pnum, SPL_HEALOTHER); ++j) { + for (j = 0; j < GetSpellLevel(pnum, SPL_HEALOTHER); ++j) { hp += (random(57, 6) + 1) << 6; }