Browse Source

Make DirecX usage C compatible

pull/25/head
Anders Jenbo 7 years ago
parent
commit
86018b174b
  1. 2
      MakefileVC
  2. 17
      Source/capture.cpp
  3. 74
      Source/dx.cpp
  4. 18
      Source/palette.cpp
  5. 26
      Source/scrollrt.cpp
  6. 96
      Source/sound.cpp

2
MakefileVC

@ -58,7 +58,7 @@ DIABLO_SRC += Source/render.cpp
OBJS=$(DIABLO_SRC:.cpp=.obj)
# hardcoded list of src files, because only some of them are ready to be compiled as C instead of C++
# once all files compile as C we should use the /TC flag abd DIABLO_SRC instead
DIABLO_SRC_FIXED = Source/appfat.cpp /TcSource/automap.cpp Source/capture.cpp /TcSource/codec.cpp Source/control.cpp /TcSource/cursor.cpp /TcSource/dead.cpp /TcSource/debug.cpp Source/diablo.cpp /TcSource/doom.cpp /TcSource/drlg_l1.cpp /TcSource/drlg_l2.cpp Source/drlg_l3.cpp /TcSource/drlg_l4.cpp Source/dthread.cpp Source/dx.cpp /TcSource/effects.cpp /TcSource/encrypt.cpp Source/engine.cpp /TcSource/error.cpp Source/fault.cpp /TcSource/gamemenu.cpp /TcSource/gendung.cpp /TcSource/gmenu.cpp /TcSource/help.cpp /TcSource/init.cpp /TcSource/interfac.cpp /TcSource/inv.cpp Source/items.cpp Source/lighting.cpp /TcSource/loadsave.cpp Source/logging.cpp /TcSource/mainmenu.cpp /TcSource/minitext.cpp /TcSource/missiles.cpp Source/monster.cpp /TcSource/movie.cpp Source/mpqapi.cpp /TcSource/msg.cpp Source/msgcmd.cpp /TcSource/multi.cpp Source/nthread.cpp Source/objects.cpp /TcSource/pack.cpp Source/palette.cpp /TcSource/path.cpp /TcSource/pfile.cpp /TcSource/player.cpp /TcSource/plrmsg.cpp /TcSource/portal.cpp /TcSource/quests.cpp /TcSource/restrict.cpp Source/scrollrt.cpp /TcSource/setmaps.cpp /TcSource/sha.cpp Source/sound.cpp /TcSource/spells.cpp Source/stores.cpp /TcSource/sync.cpp /TcSource/textdat.cpp /TcSource/themes.cpp /TcSource/tmsg.cpp /TcSource/town.cpp /TcSource/towners.cpp /TcSource/track.cpp /TcSource/trigs.cpp /TcSource/wave.cpp Source/render.cpp
DIABLO_SRC_FIXED = Source/appfat.cpp /TcSource/automap.cpp /TcSource/capture.cpp /TcSource/codec.cpp Source/control.cpp /TcSource/cursor.cpp /TcSource/dead.cpp /TcSource/debug.cpp Source/diablo.cpp /TcSource/doom.cpp /TcSource/drlg_l1.cpp /TcSource/drlg_l2.cpp Source/drlg_l3.cpp /TcSource/drlg_l4.cpp Source/dthread.cpp Source/dx.cpp /TcSource/effects.cpp /TcSource/encrypt.cpp Source/engine.cpp /TcSource/error.cpp Source/fault.cpp /TcSource/gamemenu.cpp /TcSource/gendung.cpp /TcSource/gmenu.cpp /TcSource/help.cpp /TcSource/init.cpp /TcSource/interfac.cpp /TcSource/inv.cpp Source/items.cpp Source/lighting.cpp /TcSource/loadsave.cpp Source/logging.cpp /TcSource/mainmenu.cpp /TcSource/minitext.cpp /TcSource/missiles.cpp Source/monster.cpp /TcSource/movie.cpp Source/mpqapi.cpp /TcSource/msg.cpp Source/msgcmd.cpp /TcSource/multi.cpp Source/nthread.cpp Source/objects.cpp /TcSource/pack.cpp /TcSource/palette.cpp /TcSource/path.cpp /TcSource/pfile.cpp /TcSource/player.cpp /TcSource/plrmsg.cpp /TcSource/portal.cpp /TcSource/quests.cpp /TcSource/restrict.cpp /TcSource/scrollrt.cpp /TcSource/setmaps.cpp /TcSource/sha.cpp /TcSource/sound.cpp /TcSource/spells.cpp Source/stores.cpp /TcSource/sync.cpp /TcSource/textdat.cpp /TcSource/themes.cpp /TcSource/tmsg.cpp /TcSource/town.cpp /TcSource/towners.cpp /TcSource/track.cpp /TcSource/trigs.cpp /TcSource/wave.cpp Source/render.cpp
PKWARE_SRC=$(sort $(wildcard 3rdParty/PKWare/*.cpp))
PKWARE_OBJS=$(PKWARE_SRC:.cpp=.obj)

17
Source/capture.cpp

@ -12,7 +12,11 @@ void __cdecl CaptureScreen()
hObject = CaptureFile(FileName);
if (hObject != INVALID_HANDLE_VALUE) {
DrawAndBlit();
#ifdef __cplusplus
lpDDPalette->GetEntries(0, 0, 256, palette);
#else
lpDDPalette->lpVtbl->GetEntries(lpDDPalette, 0, 0, 256, palette);
#endif
RedPalette(palette);
j_lock_buf_priv(2);
@ -30,7 +34,11 @@ void __cdecl CaptureScreen()
DeleteFile(FileName);
Sleep(300);
#ifdef __cplusplus
lpDDPalette->SetEntries(0, 0, 256, palette);
#else
lpDDPalette->lpVtbl->SetEntries(lpDDPalette, 0, 0, 256, palette);
#endif
}
}
@ -134,7 +142,7 @@ HANDLE __fastcall CaptureFile(char *dst_path)
{
BOOLEAN num_used[100];
int free_num, hFind;
_finddata_t finder;
struct _finddata_t finder;
memset(num_used, FALSE, sizeof(num_used));
hFind = _findfirst("screen??.PCX", &finder);
@ -161,13 +169,18 @@ HANDLE __fastcall CaptureFile(char *dst_path)
void __fastcall RedPalette(PALETTEENTRY *pal)
{
PALETTEENTRY red[256];
int i;
for (int i = 0; i < 256; i++) {
for (i = 0; i < 256; i++) {
red[i].peRed = pal[i].peRed;
red[i].peGreen = 0;
red[i].peBlue = 0;
red[i].peFlags = 0;
}
#ifdef __cplusplus
lpDDPalette->SetEntries(0, 0, 256, red);
#else
lpDDPalette->lpVtbl->SetEntries(lpDDPalette, 0, 0, 256, red);
#endif
}

74
Source/dx.cpp

@ -3,7 +3,6 @@
#include "../types.h"
Screen *sgpBackBuf;
static float dx_cpp_init_value = INFINITY;
LPDIRECTDRAW lpDDInterface;
IDirectDrawPalette *lpDDPalette; // idb
int sgdwLockCount;
@ -64,16 +63,28 @@ void __fastcall dx_init(HWND hWnd)
if (v3)
ErrDlg(IDD_DIALOG1, v3, "C:\\Src\\Diablo\\Source\\dx.cpp", 149);
fullscreen = 1;
#ifdef __cplusplus
v4 = lpDDInterface->SetCooperativeLevel(v1, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN);
#else
v4 = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, v1, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN);
#endif
if (v4 == DDERR_EXCLUSIVEMODEALREADYSET) {
MI_Dummy(0); // v5
} else if (v4) {
ErrDlg(IDD_DIALOG1, v4, "C:\\Src\\Diablo\\Source\\dx.cpp", 170);
}
#ifdef __cplusplus
if (lpDDInterface->SetDisplayMode(640, 480, 8)) {
#else
if (lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, 640, 480, 8)) {
#endif
v6 = GetSystemMetrics(SM_CXSCREEN);
v7 = GetSystemMetrics(SM_CYSCREEN);
#ifdef __cplusplus
v8 = lpDDInterface->SetDisplayMode(v6, v7, 8);
#else
v8 = lpDDInterface->lpVtbl->SetDisplayMode(lpDDInterface, v6, v7, 8);
#endif
if (v8)
ErrDlg(IDD_DIALOG1, v8, "C:\\Src\\Diablo\\Source\\dx.cpp", 183);
}
@ -91,15 +102,27 @@ void __cdecl dx_create_back_buffer()
HRESULT error_code;
DDSURFACEDESC ddsd;
#ifdef __cplusplus
error_code = lpDDSPrimary->GetCaps(&caps);
#else
error_code = lpDDSPrimary->lpVtbl->GetCaps(lpDDSPrimary, &caps);
#endif
if (error_code != DD_OK)
DDErrMsg(error_code, 59, "C:\\Src\\Diablo\\Source\\dx.cpp");
if (gbBackBuf == NULL) {
if (!gbBackBuf) {
ddsd.dwSize = sizeof(ddsd);
#ifdef __cplusplus
error_code = lpDDSPrimary->Lock(NULL, &ddsd, DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
#else
error_code = lpDDSPrimary->lpVtbl->Lock(lpDDSPrimary, NULL, &ddsd, DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
#endif
if (error_code == DD_OK) {
#ifdef __cplusplus
lpDDSPrimary->Unlock(NULL);
#else
lpDDSPrimary->lpVtbl->Unlock(lpDDSPrimary, NULL);
#endif
sgpBackBuf = (Screen *)DiabloAllocPtr(sizeof(Screen));
return;
}
@ -115,10 +138,18 @@ void __cdecl dx_create_back_buffer()
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
ddsd.dwHeight = 656;
ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
#ifdef __cplusplus
error_code = lpDDSPrimary->GetPixelFormat(&ddsd.ddpfPixelFormat);
#else
error_code = lpDDSPrimary->lpVtbl->GetPixelFormat(lpDDSPrimary, &ddsd.ddpfPixelFormat);
#endif
if (error_code != DD_OK)
ErrDlg(IDD_DIALOG1, error_code, "C:\\Src\\Diablo\\Source\\dx.cpp", 94);
#ifdef __cplusplus
error_code = lpDDInterface->CreateSurface(&ddsd, &lpDDSBackBuf, NULL);
#else
error_code = lpDDInterface->lpVtbl->CreateSurface(lpDDInterface, &ddsd, &lpDDSBackBuf, NULL);
#endif
if (error_code != DD_OK)
ErrDlg(IDD_DIALOG1, error_code, "C:\\Src\\Diablo\\Source\\dx.cpp", 96);
}
@ -133,13 +164,20 @@ void __cdecl dx_create_primary_surface()
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
#ifdef __cplusplus
error_code = lpDDInterface->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
#else
error_code = lpDDInterface->lpVtbl->CreateSurface(lpDDInterface, &ddsd, &lpDDSPrimary, NULL);
#endif
if (error_code != DD_OK)
ErrDlg(IDD_DIALOG1, error_code, "C:\\Src\\Diablo\\Source\\dx.cpp", 109);
}
HRESULT __fastcall dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter)
{
HRESULT(WINAPI * DirectDrawCreate)
(LPGUID lpGuid, LPDIRECTDRAW * lplpDD, LPUNKNOWN pUnkOuter);
if (ghDiabMod == NULL) {
ghDiabMod = LoadLibrary("ddraw.dll");
if (ghDiabMod == NULL) {
@ -147,8 +185,6 @@ HRESULT __fastcall dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKN
}
}
HRESULT(WINAPI * DirectDrawCreate)
(LPGUID lpGuid, LPDIRECTDRAW * lplpDD, LPUNKNOWN pUnkOuter);
DirectDrawCreate = (HRESULT(WINAPI *)(LPGUID, LPDIRECTDRAW *, LPUNKNOWN))GetProcAddress(ghDiabMod, "DirectDrawCreate");
if (DirectDrawCreate == NULL) {
ErrDlg(IDD_DIALOG4, GetLastError(), "C:\\Src\\Diablo\\Source\\dx.cpp", 127);
@ -188,7 +224,11 @@ void __cdecl lock_buf_priv()
return;
}
ddsd.dwSize = sizeof(ddsd);
#ifdef __cplusplus
error_code = lpDDSBackBuf->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
#else
error_code = lpDDSBackBuf->lpVtbl->Lock(lpDDSBackBuf, NULL, &ddsd, DDLOCK_WAIT, NULL);
#endif
if (error_code != DD_OK)
DDErrMsg(error_code, 235, "C:\\Src\\Diablo\\Source\\dx.cpp");
@ -221,7 +261,11 @@ void __cdecl unlock_buf_priv()
gpBufEnd -= (int)gpBuffer;
gpBuffer = NULL;
if (sgpBackBuf == NULL) {
#ifdef __cplusplus
error_code = lpDDSBackBuf->Unlock(NULL);
#else
error_code = lpDDSBackBuf->lpVtbl->Unlock(lpDDSBackBuf, NULL);
#endif
if (error_code != DD_OK)
DDErrMsg(error_code, 273, "C:\\Src\\Diablo\\Source\\dx.cpp");
}
@ -242,23 +286,39 @@ void __cdecl dx_cleanup()
sgpBackBuf = 0;
mem_free_dbg(v0);
} else if (lpDDSBackBuf != NULL) {
#ifdef __cplusplus
lpDDSBackBuf->Release();
#else
lpDDSBackBuf->lpVtbl->Release(lpDDSBackBuf);
#endif
lpDDSBackBuf = NULL;
}
sgdwLockCount = 0;
gpBuffer = 0;
LeaveCriticalSection(&sgMemCrit);
if (lpDDSPrimary) {
#ifdef __cplusplus
lpDDSPrimary->Release();
lpDDSPrimary = 0;
#else
lpDDSPrimary->lpVtbl->Release(lpDDSPrimary);
#endif
lpDDSPrimary = NULL;
}
if (lpDDPalette) {
#ifdef __cplusplus
lpDDPalette->Release();
lpDDPalette = 0;
#else
lpDDPalette->lpVtbl->Release(lpDDPalette);
#endif
lpDDPalette = NULL;
}
if (lpDDInterface) {
#ifdef __cplusplus
lpDDInterface->Release();
lpDDInterface = 0;
#else
lpDDInterface->lpVtbl->Release(lpDDInterface);
#endif
lpDDInterface = NULL;
}
}

18
Source/palette.cpp

@ -3,7 +3,6 @@
#include "../types.h"
PALETTEENTRY logical_palette[256];
static float palette_cpp_init_value = INFINITY;
PALETTEENTRY system_palette[256];
PALETTEENTRY orig_palette[256];
UINT gdwPalEntries;
@ -28,10 +27,18 @@ void __cdecl palette_init()
LoadGamma();
memcpy(system_palette, orig_palette, 0x400u);
LoadSysPal();
#ifdef __cplusplus
v0 = lpDDInterface->CreatePalette(DDPCAPS_ALLOW256 | DDPCAPS_8BIT, system_palette, &lpDDPalette, NULL);
#else
v0 = lpDDInterface->lpVtbl->CreatePalette(lpDDInterface, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, system_palette, &lpDDPalette, NULL);
#endif
if (v0)
ErrDlg(IDD_DIALOG8, v0, "C:\\Src\\Diablo\\Source\\PALETTE.CPP", 143);
#ifdef __cplusplus
v1 = lpDDSPrimary->SetPalette(lpDDPalette);
#else
v1 = lpDDSPrimary->lpVtbl->SetPalette(lpDDSPrimary, lpDDPalette);
#endif
if (v1)
ErrDlg(IDD_DIALOG8, v1, "C:\\Src\\Diablo\\Source\\PALETTE.CPP", 146);
}
@ -118,8 +125,13 @@ void __fastcall LoadRndLvlPal(int l)
void __cdecl ResetPal()
{
if (!lpDDSPrimary
#ifdef __cplusplus
|| lpDDSPrimary->IsLost() != DDERR_SURFACELOST
|| !lpDDSPrimary->Restore()) {
#else
|| lpDDSPrimary->lpVtbl->IsLost(lpDDSPrimary) != DDERR_SURFACELOST
|| !lpDDSPrimary->lpVtbl->Restore(lpDDSPrimary)) {
#endif
SDrawRealizePalette();
}
}
@ -209,7 +221,11 @@ void __fastcall SetFadeLevel(int fadeval)
system_palette[i].peBlue = (fadeval * logical_palette[i].peBlue) >> 8;
}
Sleep(3);
#ifdef __cplusplus
lpDDInterface->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
#else
lpDDInterface->lpVtbl->WaitForVerticalBlank(lpDDInterface, DDWAITVB_BLOCKBEGIN, NULL);
#endif
palette_update();
}
}

26
Source/scrollrt.cpp

@ -4,7 +4,6 @@
int light_table_index; // weak
int screen_y_times_768[1024];
static float scrollrt_cpp_init_value = INFINITY;
unsigned int sgdwCursWdtOld; // idb
int sgdwCursX; // idb
int sgdwCursY; // idb
@ -2800,9 +2799,15 @@ void __fastcall DrawMain(int dwHgt, int draw_desc, int draw_hp, int draw_mana, i
a4 = dwHgt;
if (gbActive && lpDDSPrimary) {
#ifdef __cplusplus
if (lpDDSPrimary->IsLost() == DDERR_SURFACELOST) {
if (lpDDSPrimary->Restore())
return;
#else
if (lpDDSPrimary->lpVtbl->IsLost(lpDDSPrimary) == DDERR_SURFACELOST) {
if (lpDDSPrimary->lpVtbl->Restore(lpDDSPrimary))
return;
#endif
ResetPal();
a4 = 480;
}
@ -2812,7 +2817,11 @@ void __fastcall DrawMain(int dwHgt, int draw_desc, int draw_hp, int draw_mana, i
v7 = GetTickCount();
while (1) {
DDS_desc.dwSize = 108;
#ifdef __cplusplus
v8 = lpDDSPrimary->Lock(NULL, &DDS_desc, DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
#else
v8 = lpDDSPrimary->lpVtbl->Lock(lpDDSPrimary, NULL, &DDS_desc, DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
#endif
if (!v8)
break;
if (v7 - GetTickCount() > 5000)
@ -2863,7 +2872,11 @@ void __fastcall DrawMain(int dwHgt, int draw_desc, int draw_hp, int draw_mana, i
DoBlitScreen(sgdwCursX, sgdwCursY, sgdwCursWdt, sgdwCursHgt);
}
if (lpDDSBackBuf == NULL) {
#ifdef __cplusplus
v9 = lpDDSPrimary->Unlock(NULL);
#else
v9 = lpDDSPrimary->lpVtbl->Unlock(lpDDSPrimary, NULL);
#endif
if (v9 != DDERR_SURFACELOST) {
if (v9)
DDErrMsg(v9, 3779, "C:\\Src\\Diablo\\Source\\SCROLLRT.CPP");
@ -2897,10 +2910,17 @@ void __cdecl DrawFPS()
if (framerate > 99)
framerate = 99;
wsprintf(String, "%2d", framerate);
#ifdef __cplusplus
if (!lpDDSPrimary->GetDC(&hdc)) {
TextOut(hdc, 0, 400, String, strlen(String));
lpDDSPrimary->ReleaseDC(hdc);
}
#else
if (!lpDDSPrimary->lpVtbl->GetDC(lpDDSPrimary, &hdc)) {
TextOut(hdc, 0, 400, String, strlen(String));
lpDDSPrimary->lpVtbl->ReleaseDC(lpDDSPrimary, hdc);
}
#endif
}
}
#endif
@ -2931,7 +2951,11 @@ void __fastcall DoBlitScreen(int dwX, int dwY, int dwWdt, int dwHgt)
Rect.bottom = dwY + 160 + dwHgt - 1;
a4 = GetTickCount();
while (1) {
#ifdef __cplusplus
error_code = lpDDSPrimary->BltFast(v5, v4, lpDDSBackBuf, &Rect, DDBLTFAST_WAIT);
#else
error_code = lpDDSPrimary->lpVtbl->BltFast(lpDDSPrimary, v5, v4, lpDDSBackBuf, &Rect, DDBLTFAST_WAIT);
#endif
if (!error_code)
break;
if (a4 - GetTickCount() <= 5000) {

96
Source/sound.cpp

@ -2,7 +2,6 @@
#include "../types.h"
static float sound_cpp_init_value = INFINITY;
LPDIRECTSOUNDBUFFER DSBs[8];
LPDIRECTSOUND sglpDS;
char gbSndInited;
@ -41,11 +40,20 @@ void __fastcall snd_update(BOOL bStopAll)
if (!DSBs[i])
continue;
#ifdef __cplusplus
if (!bStopAll && !DSBs[i]->GetStatus(&error_code) && error_code == DSBSTATUS_PLAYING)
continue;
DSBs[i]->Stop();
DSBs[i]->Release();
#else
if (!bStopAll && !DSBs[i]->lpVtbl->GetStatus(DSBs[i], &error_code) && error_code == DSBSTATUS_PLAYING)
continue;
DSBs[i]->lpVtbl->Stop(DSBs[i]);
DSBs[i]->lpVtbl->Release(DSBs[i]);
#endif
DSBs[i] = NULL;
}
}
@ -53,7 +61,11 @@ void __fastcall snd_update(BOOL bStopAll)
void __fastcall snd_stop_snd(TSnd *pSnd)
{
if (pSnd && pSnd->DSB)
#ifdef __cplusplus
pSnd->DSB->Stop();
#else
pSnd->DSB->lpVtbl->Stop(pSnd->DSB);
#endif
}
BOOL __fastcall snd_playing(TSnd *pSnd)
@ -66,7 +78,11 @@ BOOL __fastcall snd_playing(TSnd *pSnd)
if (pSnd->DSB == NULL)
return FALSE;
#ifdef __cplusplus
if (pSnd->DSB->GetStatus(&error_code))
#else
if (pSnd->DSB->lpVtbl->GetStatus(pSnd->DSB, &error_code))
#endif
return FALSE;
return error_code == DSBSTATUS_PLAYING;
@ -95,7 +111,7 @@ void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
if (snd_playing(pSnd)) {
DSB = sound_dup_channel(pSnd->DSB);
if (DSB == 0) {
if (DSB == NULL) {
return;
}
}
@ -106,17 +122,29 @@ void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
} else if (lVolume > VOLUME_MAX) {
lVolume = VOLUME_MAX;
}
#ifdef __cplusplus
DSB->SetVolume(lVolume);
DSB->SetPan(lPan);
error_code = DSB->Play(0, 0, 0);
#else
DSB->lpVtbl->SetVolume(DSB, lVolume);
DSB->lpVtbl->SetPan(DSB, lPan);
error_code = DSB->lpVtbl->Play(DSB, 0, 0, 0);
#endif
if (error_code != DSERR_BUFFERLOST) {
if (error_code != DS_OK) {
DSErrMsg(error_code, 261, "C:\\Src\\Diablo\\Source\\SOUND.CPP");
}
} else if (sound_file_reload(pSnd, DSB)) {
#ifdef __cplusplus
DSB->Play(0, 0, 0);
#else
DSB->lpVtbl->Play(DSB, 0, 0, 0);
#endif
}
pSnd->start_tc = tc;
@ -132,7 +160,11 @@ LPDIRECTSOUNDBUFFER __fastcall sound_dup_channel(LPDIRECTSOUNDBUFFER DSB)
for (i = 0; i < 8; i++) {
if (!DSBs[i]) {
#ifdef __cplusplus
if (sglpDS->DuplicateSoundBuffer(DSB, &DSBs[i]) != DS_OK) {
#else
if (sglpDS->lpVtbl->DuplicateSoundBuffer(sglpDS, DSB, &DSBs[i]) != DS_OK) {
#endif
return NULL;
}
@ -150,19 +182,31 @@ BOOL __fastcall sound_file_reload(TSnd *sound_file, LPDIRECTSOUNDBUFFER DSB)
DWORD size1, size2;
BOOL rv;
#ifdef __cplusplus
if (DSB->Restore())
#else
if (DSB->lpVtbl->Restore(DSB))
#endif
return FALSE;
rv = FALSE;
WOpenFile(sound_file->sound_path, &file, 0);
WSetFilePointer(file, sound_file->chunk.dwOffset, 0, 0);
#ifdef __cplusplus
if (DSB->Lock(0, sound_file->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0) == DS_OK) {
WReadFile(file, buf1, size1);
if (DSB->Unlock(buf1, size1, buf2, size2) == DS_OK) {
if (DSB->Unlock(buf1, size1, buf2, size2) == DS_OK)
rv = TRUE;
}
#else
if (DSB->lpVtbl->Lock(DSB, 0, sound_file->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0) == DS_OK) {
WReadFile(file, buf1, size1);
if (DSB->lpVtbl->Unlock(DSB, buf1, size1, buf2, size2) == DS_OK)
rv = TRUE;
}
}
#endif
WCloseFile(file);
@ -192,13 +236,21 @@ TSnd *__fastcall sound_file_load(char *path)
sound_CreateSoundBuffer(pSnd);
#ifdef __cplusplus
error_code = pSnd->DSB->Lock(0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0);
#else
error_code = pSnd->DSB->lpVtbl->Lock(pSnd->DSB, 0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0);
#endif
if (error_code != DS_OK)
DSErrMsg(error_code, 318, "C:\\Src\\Diablo\\Source\\SOUND.CPP");
memcpy(buf1, (char *)wave_file + pSnd->chunk.dwOffset, size1);
#ifdef __cplusplus
error_code = pSnd->DSB->Unlock(buf1, size1, buf2, size2);
#else
error_code = pSnd->DSB->lpVtbl->Unlock(pSnd->DSB, buf1, size1, buf2, size2);
#endif
if (error_code != DS_OK)
DSErrMsg(error_code, 325, "C:\\Src\\Diablo\\Source\\SOUND.CPP");
@ -220,7 +272,11 @@ void __fastcall sound_CreateSoundBuffer(TSnd *sound_file)
DSB.dwSize = sizeof(DSBUFFERDESC);
DSB.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_STATIC;
#ifdef __cplusplus
error_code = sglpDS->CreateSoundBuffer(&DSB, &sound_file->DSB, NULL);
#else
error_code = sglpDS->lpVtbl->CreateSoundBuffer(sglpDS, &DSB, &sound_file->DSB, NULL);
#endif
if (error_code != ERROR_SUCCESS)
DSErrMsg(error_code, 282, "C:\\Src\\Diablo\\Source\\SOUND.CPP");
}
@ -229,8 +285,13 @@ void __fastcall sound_file_cleanup(TSnd *sound_file)
{
if (sound_file) {
if (sound_file->DSB) {
#ifdef __cplusplus
sound_file->DSB->Stop();
sound_file->DSB->Release();
#else
sound_file->DSB->lpVtbl->Stop(sound_file->DSB);
sound_file->DSB->lpVtbl->Release(sound_file->DSB);
#endif
sound_file->DSB = NULL;
}
@ -249,7 +310,11 @@ void __fastcall snd_init(HWND hWnd)
if (sound_DirectSoundCreate(NULL, &sglpDS, NULL) != DS_OK)
sglpDS = NULL;
#ifdef __cplusplus
if (sglpDS && sglpDS->SetCooperativeLevel(hWnd, DSSCL_EXCLUSIVE) == DS_OK)
#else
if (sglpDS && sglpDS->lpVtbl->SetCooperativeLevel(sglpDS, hWnd, DSSCL_EXCLUSIVE) == DS_OK)
#endif
sound_create_primary_buffer(0);
SVidInitialize(sglpDS);
@ -285,7 +350,11 @@ void __fastcall sound_create_primary_buffer(HANDLE music_track)
dsbuf.dwSize = sizeof(DSBUFFERDESC);
dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER;
#ifdef __cplusplus
error_code = sglpDS->CreateSoundBuffer(&dsbuf, &sglpDSB, NULL);
#else
error_code = sglpDS->lpVtbl->CreateSoundBuffer(sglpDS, &dsbuf, &sglpDSB, NULL);
#endif
if (error_code != DS_OK)
DSErrMsg(error_code, 375, "C:\\Src\\Diablo\\Source\\SOUND.CPP");
}
@ -294,7 +363,11 @@ void __fastcall sound_create_primary_buffer(HANDLE music_track)
DSCAPS dsbcaps;
dsbcaps.dwSize = sizeof(DSCAPS);
#ifdef __cplusplus
error_code = sglpDS->GetCaps(&dsbcaps);
#else
error_code = sglpDS->lpVtbl->GetCaps(sglpDS, &dsbcaps);
#endif
if (error_code != DS_OK)
DSErrMsg(error_code, 383, "C:\\Src\\Diablo\\Source\\SOUND.CPP");
@ -310,13 +383,20 @@ void __fastcall sound_create_primary_buffer(HANDLE music_track)
format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
#ifdef __cplusplus
sglpDSB->SetFormat(&format);
#else
sglpDSB->lpVtbl->SetFormat(sglpDSB, &format);
#endif
}
}
// 69F100: using guessed type int sglpDSB;
HRESULT __fastcall sound_DirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter)
{
HRESULT(WINAPI * DirectSoundCreate)
(LPGUID lpGuid, LPDIRECTSOUND * ppDS, LPUNKNOWN pUnkOuter);
if (hDsound_dll == NULL) {
hDsound_dll = LoadLibrary("dsound.dll");
if (hDsound_dll == NULL) {
@ -324,8 +404,6 @@ HRESULT __fastcall sound_DirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND *ppDS, L
}
}
HRESULT(WINAPI * DirectSoundCreate)
(LPGUID lpGuid, LPDIRECTSOUND * ppDS, LPUNKNOWN pUnkOuter);
DirectSoundCreate = (HRESULT(WINAPI *)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN))GetProcAddress(hDsound_dll, "DirectSoundCreate");
if (DirectSoundCreate == NULL) {
ErrDlg(IDD_DIALOG5, GetLastError(), "C:\\Src\\Diablo\\Source\\SOUND.CPP", 427);
@ -340,7 +418,11 @@ void __cdecl sound_cleanup()
SFileDdaDestroy();
if (sglpDS) {
#ifdef __cplusplus
sglpDS->Release();
#else
sglpDS->lpVtbl->Release(sglpDS);
#endif
sglpDS = NULL;
}

Loading…
Cancel
Save