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 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;

3
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 */

13
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;

57
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");
}

3
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;

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)
{
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;
}

Loading…
Cancel
Save