Browse Source

C compatability from s (#521)

pull/25/head
Anders Jenbo 7 years ago committed by Robin Eklind
parent
commit
024d99fc9e
  1. 13
      Source/scrollrt.cpp
  2. 3
      Source/scrollrt.h
  3. 13
      Source/sha.cpp
  4. 57
      Source/sound.cpp
  5. 3
      Source/sound.h
  6. 33
      Source/spells.cpp

13
Source/scrollrt.cpp

@ -4,7 +4,7 @@
int light_table_index; // weak int light_table_index; // weak
int screen_y_times_768[1024]; int screen_y_times_768[1024];
int scrollrt_cpp_init_value; // weak static float scrollrt_cpp_init_value = INFINITY;
unsigned int sgdwCursWdtOld; // idb unsigned int sgdwCursWdtOld; // idb
int sgdwCursX; // idb int sgdwCursX; // idb
int sgdwCursY; // idb int sgdwCursY; // idb
@ -23,8 +23,6 @@ char sgSaveBack[8192];
int draw_monster_num; // weak int draw_monster_num; // weak
int sgdwCursHgtOld; // idb int sgdwCursHgtOld; // idb
const int scrollrt_inf = 0x7F800000; // weak
/* data */ /* data */
/* used in 1.00 debug */ /* used in 1.00 debug */
@ -64,15 +62,6 @@ char *szPlrModeAssert[12] = {
"quitting" "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 void __cdecl ClearCursor() // CODE_FIX: this was supposed to be in cursor.cpp
{ {
sgdwCursWdt = 0; sgdwCursWdt = 0;

3
Source/scrollrt.h

@ -4,7 +4,6 @@
extern int light_table_index; // weak extern int light_table_index; // weak
extern int screen_y_times_768[1024]; extern int screen_y_times_768[1024];
extern int scrollrt_cpp_init_value; // weak
extern unsigned int sgdwCursWdtOld; // idb extern unsigned int sgdwCursWdtOld; // idb
extern int sgdwCursX; // idb extern int sgdwCursX; // idb
extern int sgdwCursY; // idb extern int sgdwCursY; // idb
@ -63,8 +62,6 @@ void __cdecl DrawAndBlit();
/* rdata */ /* rdata */
extern const int scrollrt_inf; // weak
/* data */ /* data */
/* used in 1.00 debug */ /* used in 1.00 debug */

13
Source/sha.cpp

@ -11,9 +11,12 @@ void __cdecl SHA1Clear()
void __fastcall SHA1Result(int n, char Message_Digest[SHA1HashSize]) 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) { 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 = sgSHA1[n].state[i];
Message_Digest_Block++; 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) 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]) if (count < context->count[0])
context->count[1]++; context->count[1]++;
context->count[0] = count; context->count[0] = count;
context->count[1] += len >> 29; 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)); memcpy(context->buffer, message_array, sizeof(context->buffer));
SHA1ProcessMessageBlock(context); SHA1ProcessMessageBlock(context);
message_array += 64; message_array += 64;

57
Source/sound.cpp

@ -2,7 +2,7 @@
#include "../types.h" #include "../types.h"
float sound_cpp_init_value; static float sound_cpp_init_value = INFINITY;
LPDIRECTSOUNDBUFFER DSBs[8]; LPDIRECTSOUNDBUFFER DSBs[8];
LPDIRECTSOUND sglpDS; LPDIRECTSOUND sglpDS;
char gbSndInited; char gbSndInited;
@ -12,8 +12,6 @@ HMODULE hDsound_dll;
HANDLE sgpMusicTrack; HANDLE sgpMusicTrack;
LPDIRECTSOUNDBUFFER sglpDSB; LPDIRECTSOUNDBUFFER sglpDSB;
const int sound_inf = 0x7F800000; // weak
/* data */ /* data */
BYTE gbMusicOn = TRUE; BYTE gbMusicOn = TRUE;
@ -35,19 +33,11 @@ char unk_volume[4][2] = {
{ 30, -31 } { 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) 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]) if (!DSBs[i])
continue; continue;
@ -68,7 +58,7 @@ void __fastcall snd_stop_snd(TSnd *pSnd)
BOOL __fastcall snd_playing(TSnd *pSnd) BOOL __fastcall snd_playing(TSnd *pSnd)
{ {
DWORD error_code; DWORD error_code; // TODO should probably be HRESULT
if (!pSnd) if (!pSnd)
return FALSE; return FALSE;
@ -84,16 +74,20 @@ BOOL __fastcall snd_playing(TSnd *pSnd)
void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan) void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
{ {
LPDIRECTSOUNDBUFFER DSB;
DWORD tc;
HRESULT error_code;
if (!pSnd || !gbSoundOn) { if (!pSnd || !gbSoundOn) {
return; return;
} }
LPDIRECTSOUNDBUFFER DSB = pSnd->DSB; DSB = pSnd->DSB;
if (!DSB) { if (!DSB) {
return; return;
} }
DWORD tc = GetTickCount(); tc = GetTickCount();
if (tc - pSnd->start_tc < 80) { if (tc - pSnd->start_tc < 80) {
pSnd->start_tc = GetTickCount(); pSnd->start_tc = GetTickCount();
return; return;
@ -116,7 +110,7 @@ void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
DSB->SetPan(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 != DSERR_BUFFERLOST) {
if (error_code != DS_OK) { if (error_code != DS_OK) {
DSErrMsg(error_code, 261, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); 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) LPDIRECTSOUNDBUFFER __fastcall sound_dup_channel(LPDIRECTSOUNDBUFFER DSB)
{ {
DWORD i;
if (!gbDupSounds) { if (!gbDupSounds) {
return NULL; return NULL;
} }
for (DWORD i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (!DSBs[i]) { if (!DSBs[i]) {
if (sglpDS->DuplicateSoundBuffer(DSB, &DSBs[i]) != DS_OK) { if (sglpDS->DuplicateSoundBuffer(DSB, &DSBs[i]) != DS_OK) {
return NULL; return NULL;
@ -149,14 +145,15 @@ LPDIRECTSOUNDBUFFER __fastcall sound_dup_channel(LPDIRECTSOUNDBUFFER DSB)
BOOL __fastcall sound_file_reload(TSnd *sound_file, LPDIRECTSOUNDBUFFER DSB) BOOL __fastcall sound_file_reload(TSnd *sound_file, LPDIRECTSOUNDBUFFER DSB)
{ {
if (DSB->Restore())
return FALSE;
HANDLE file; HANDLE file;
LPVOID buf1, buf2; LPVOID buf1, buf2;
DWORD size1, size2; DWORD size1, size2;
BOOL rv;
BOOL rv = FALSE; if (DSB->Restore())
return FALSE;
rv = FALSE;
WOpenFile(sound_file->sound_path, &file, 0); WOpenFile(sound_file->sound_path, &file, 0);
WSetFilePointer(file, sound_file->chunk.dwOffset, 0, 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) TSnd *__fastcall sound_file_load(char *path)
{ {
void *file, *wave_file;
TSnd *pSnd;
LPVOID buf1, buf2;
DWORD size1, size2;
HRESULT error_code;
if (!sglpDS) if (!sglpDS)
return NULL; return NULL;
void *file, *wave_file;
WOpenFile(path, &file, 0); WOpenFile(path, &file, 0);
TSnd *pSnd = (TSnd *)DiabloAllocPtr(40); pSnd = (TSnd *)DiabloAllocPtr(40);
memset(pSnd, 0, sizeof(TSnd)); memset(pSnd, 0, sizeof(TSnd));
pSnd->sound_path = path; pSnd->sound_path = path;
pSnd->start_tc = GetTickCount() - 81; pSnd->start_tc = GetTickCount() - 81;
@ -190,9 +192,7 @@ TSnd *__fastcall sound_file_load(char *path)
sound_CreateSoundBuffer(pSnd); sound_CreateSoundBuffer(pSnd);
LPVOID buf1, buf2; error_code = pSnd->DSB->Lock(0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0);
DWORD size1, size2;
HRESULT error_code = pSnd->DSB->Lock(0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0);
if (error_code != DS_OK) if (error_code != DS_OK)
DSErrMsg(error_code, 318, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); 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) void __fastcall sound_CreateSoundBuffer(TSnd *sound_file)
{ {
DSBUFFERDESC DSB; DSBUFFERDESC DSB;
HRESULT error_code;
memset(&DSB, 0, sizeof(DSBUFFERDESC)); memset(&DSB, 0, sizeof(DSBUFFERDESC));
DSB.dwBufferBytes = sound_file->chunk.dwSize; DSB.dwBufferBytes = sound_file->chunk.dwSize;
@ -219,7 +220,7 @@ void __fastcall sound_CreateSoundBuffer(TSnd *sound_file)
DSB.dwSize = sizeof(DSBUFFERDESC); DSB.dwSize = sizeof(DSBUFFERDESC);
DSB.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_STATIC; 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) if (error_code != ERROR_SUCCESS)
DSErrMsg(error_code, 282, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); DSErrMsg(error_code, 282, "C:\\Src\\Diablo\\Source\\SOUND.CPP");
} }

3
Source/sound.h

@ -2,7 +2,6 @@
#ifndef __SOUND_H__ #ifndef __SOUND_H__
#define __SOUND_H__ #define __SOUND_H__
extern float sound_cpp_init_value;
extern IDirectSoundBuffer *DSBs[8]; extern IDirectSoundBuffer *DSBs[8];
extern LPDIRECTSOUND sglpDS; extern LPDIRECTSOUND sglpDS;
extern char gbSndInited; extern char gbSndInited;
@ -36,8 +35,6 @@ int __fastcall sound_get_or_set_sound_volume(int volume);
/* rdata */ /* rdata */
extern const int sound_inf; // weak
/* data */ /* data */
extern BYTE gbMusicOn; extern BYTE gbMusicOn;

33
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) 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 int dir; // missile direction
// ugly switch, but generates the right code // 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; 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); 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) { if (spelldata[spl].sMissiles[0] == MIS_CBOLT) {
UseMana(id, SPL_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); 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 // rid: target player index
void __fastcall DoResurrect(int pnum, int rid) void __fastcall DoResurrect(int pnum, int rid)
{ {
int hp;
if ((char)rid != -1) { if ((char)rid != -1) {
AddMissile(plr[rid].WorldX, plr[rid].WorldY, plr[rid].WorldX, plr[rid].WorldY, 0, MIS_RESURRECTBEAM, 0, pnum, 0, 0); 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; plr[rid]._pInvincible = 0;
PlacePlayer(rid); PlacePlayer(rid);
int hp = 640; hp = 640;
if (plr[rid]._pMaxHPBase < 640) { if (plr[rid]._pMaxHPBase < 640) {
hp = plr[rid]._pMaxHPBase; hp = plr[rid]._pMaxHPBase;
} }
@ -233,11 +235,12 @@ void __fastcall DoResurrect(int pnum, int rid)
void __fastcall PlacePlayer(int pnum) void __fastcall PlacePlayer(int pnum)
{ {
int nx; int nx, ny, max, min, x, y;
int ny; DWORD i;
BOOL done;
if (plr[pnum].plrlevel == currlevel) { if (plr[pnum].plrlevel == currlevel) {
for (DWORD i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
nx = plr[pnum].WorldX + plrxoff2[i]; nx = plr[pnum].WorldX + plrxoff2[i];
ny = plr[pnum].WorldY + plryoff2[i]; ny = plr[pnum].WorldY + plryoff2[i];
@ -247,13 +250,13 @@ void __fastcall PlacePlayer(int pnum)
} }
if (!PosOkPlayer(pnum, nx, ny)) { if (!PosOkPlayer(pnum, nx, ny)) {
BOOL done = FALSE; done = FALSE;
for (int max = 1, min = -1; min > -50 && !done; max++, min--) { for (max = 1, min = -1; min > -50 && !done; max++, min--) {
for (int y = min; y <= max && !done; y++) { for (y = min; y <= max && !done; y++) {
ny = plr[pnum].WorldY + 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; nx = plr[pnum].WorldX + x;
if (PosOkPlayer(pnum, nx, ny)) { if (PosOkPlayer(pnum, nx, ny)) {
@ -278,18 +281,20 @@ void __fastcall PlacePlayer(int pnum)
void __fastcall DoHealOther(int pnum, int rid) void __fastcall DoHealOther(int pnum, int rid)
{ {
int i, j, hp;
if (pnum == myplr) { if (pnum == myplr) {
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
if ((char)rid != -1 && (plr[rid]._pHitPoints >> 6) > 0) { 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; 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; hp += (random(57, 6) + 1) << 6;
} }

Loading…
Cancel
Save