Fixed the return value of play_sfall_sound function

* before it returned a raw pointer instead of the ID number of the
played sound.
This commit is contained in:
NovaRain
2020-03-12 11:58:48 +08:00
parent 0fd45aa37a
commit 0c0d1dd73e
6 changed files with 61 additions and 56 deletions
+2 -2
View File
@@ -296,8 +296,8 @@
0x8228 - int get_attack_type
0x822b - int play_sfall_sound(string file, int loop)
0x822c - void stop_sfall_sound(int ptr)
0x822b - int play_sfall_sound(string file, bool loop)
0x822c - void stop_sfall_sound(int id)
0x8235 - array string_split(string string, string split)
0x8237 - int atoi(string string)
+2 -3
View File
@@ -37,13 +37,12 @@
#include "TalkingHeads.h"
#include "Version.h"
#define SAFERELEASE(a) { if (a) { a->Release(); a = 0; } }
#define UNUSEDFUNCTION { DEBUGMESS("\n[SFALL] Unused function called: %s", __FUNCTION__); return DDERR_GENERIC; }
#define SAFERELEASE(a) { if (a) { a->Release(); a = nullptr; } }
typedef HRESULT (_stdcall *DDrawCreateProc)(void*, IDirectDraw**, void*);
typedef IDirect3D9* (_stdcall *D3DCreateProc)(UINT version);
#define UNUSEDFUNCTION { DEBUGMESS("\n[SFALL] Unused function called: %s", __FUNCTION__); return DDERR_GENERIC; }
static IDirectDrawSurface* primaryDDSurface = nullptr;
static DWORD ResWidth;
+3 -2
View File
@@ -26,14 +26,15 @@
#include "Movies.h"
#define SAFERELEASE(a) { if (a) { a->Release(); a = 0; } }
static DWORD MoviePtrs[MaxMovies];
char MoviePaths[MaxMovies * 65];
static bool aviIsReadyToPlay = false;
class CAllocator : public IVMRSurfaceAllocator9, IVMRImagePresenter9 {
#define SAFERELEASE(a) { if (a) { a->Release(); a = nullptr; } }
private:
ULONG RefCount;
IVMRSurfaceAllocatorNotify9 *pAllocNotify;
+1 -1
View File
@@ -907,7 +907,7 @@ static void _stdcall play_sfall_sound2() {
&loopArg = opHandler.arg(1);
if (fileArg.isString() && loopArg.isInt()) {
long soundID = (long)PlaySfallSound(fileArg.strValue(), loopArg.asBool());
DWORD soundID = PlaySfallSound(fileArg.strValue(), loopArg.asBool());
opHandler.setReturn(soundID);
} else {
OpcodeInvalidArgs("play_sfall_sound");
+51 -46
View File
@@ -24,10 +24,10 @@
#include "Sound.h"
#define SAFERELEASE(a) { if (a) { a->Release(); a = 0; } }
#define SAFERELEASE(a) { if (a) { a->Release(); } }
struct sDSSound {
DWORD id;
DWORD id; // should be first
IGraphBuilder *pGraph;
IMediaControl *pControl;
IMediaSeeking *pSeek;
@@ -42,7 +42,7 @@ DWORD playID = 0;
DWORD loopID = 0;
static HWND soundwindow = 0;
static void* musicLoopPtr = nullptr;
static sDSSound* musicLoopPtr = nullptr;
//static char playingMusicFile[256];
static void FreeSound(sDSSound* sound) {
@@ -56,46 +56,48 @@ static void FreeSound(sDSSound* sound) {
}
void WipeSounds() {
for (DWORD i = 0; i < playingSounds.size(); i++) FreeSound(playingSounds[i]);
for (DWORD i = 0; i < loopingSounds.size(); i++) FreeSound(loopingSounds[i]);
for (size_t i = 0; i < playingSounds.size(); i++) FreeSound(playingSounds[i]);
for (size_t i = 0; i < loopingSounds.size(); i++) FreeSound(loopingSounds[i]);
playingSounds.clear();
loopingSounds.clear();
musicLoopPtr = nullptr;
playID = 0;
loopID = 0;
}
LRESULT CALLBACK SoundWndProc(HWND wnd, UINT msg, WPARAM w, LPARAM l) {
if (msg == WM_APP) {
DWORD id = l;
sDSSound* dssound = nullptr;
sDSSound* sound = nullptr;
if (id & 0x80000000) {
for (DWORD i = 0; i < loopingSounds.size(); i++) {
for (size_t i = 0; i < loopingSounds.size(); i++) {
if (loopingSounds[i]->id == id) {
dssound = loopingSounds[i];
sound = loopingSounds[i];
break;
}
}
} else {
for (DWORD i = 0; i < playingSounds.size(); i++) {
for (size_t i = 0; i < playingSounds.size(); i++) {
if (playingSounds[i]->id == id) {
dssound = playingSounds[i];
sound = playingSounds[i];
break;
}
}
}
if (!dssound) return 0;
if (!sound) return 0;
LONG e = 0;
LONG_PTR p1 = 0, p2 = 0;
while (!FAILED(dssound->pEvent->GetEvent(&e, &p1, &p2, 0))) {
dssound->pEvent->FreeEventParams(e, p1, p2);
while (!FAILED(sound->pEvent->GetEvent(&e, &p1, &p2, 0))) {
sound->pEvent->FreeEventParams(e, p1, p2);
if (e == EC_COMPLETE) {
if (id & 0x80000000) {
LONGLONG pos = 0;
dssound->pSeek->SetPositions(&pos, AM_SEEKING_AbsolutePositioning, 0, AM_SEEKING_NoPositioning);
dssound->pControl->Run();
sound->pSeek->SetPositions(&pos, AM_SEEKING_AbsolutePositioning, 0, AM_SEEKING_NoPositioning);
sound->pControl->Run();
} else {
for (DWORD i = 0; i < playingSounds.size(); i++) {
if (playingSounds[i] == dssound) {
FreeSound(dssound);
for (size_t i = 0; i < playingSounds.size(); i++) {
if (playingSounds[i] == sound) {
FreeSound(sound);
playingSounds.erase(playingSounds.begin() + i);
return 0;
}
@@ -153,7 +155,7 @@ static void __cdecl SfallSoundVolume(sDSSound* sound, int type, long passVolume)
loopVolume = sfxVolume = -9999; // mute
} else if (type = 0) { // for music
if (musicLoopPtr) {
StopSfallSound(musicLoopPtr);
StopSfallSound(musicLoopPtr->id);
musicLoopPtr = nullptr;
}
return;
@@ -187,42 +189,42 @@ static bool IsMute(bool type) {
static sDSSound* PlayingSound(wchar_t* path, bool loop) {
if (!soundwindow) CreateSndWnd();
if (IsMute(loop)) return nullptr;
sDSSound* result = new sDSSound();
sDSSound* sound = new sDSSound();
DWORD id = (loop) ? loopID++ : playID++;
DWORD id = (loop) ? ++loopID : ++playID;
if (loop) id |= 0x80000000;
result->id = id;
sound->id = id;
HRESULT hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC, IID_IGraphBuilder, (void**)&result->pGraph);
HRESULT hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC, IID_IGraphBuilder, (void**)&sound->pGraph);
if (hr != S_OK) {
dlog_f("Error CoCreateInstance: %d", DL_INIT, hr);
return nullptr;
}
result->pGraph->QueryInterface(IID_IMediaControl, (void**)&result->pControl);
sound->pGraph->QueryInterface(IID_IMediaControl, (void**)&sound->pControl);
if (loop)
result->pGraph->QueryInterface(IID_IMediaSeeking, (void**)&result->pSeek);
sound->pGraph->QueryInterface(IID_IMediaSeeking, (void**)&sound->pSeek);
else
result->pSeek = nullptr;
sound->pSeek = nullptr;
result->pGraph->QueryInterface(IID_IMediaEventEx, (void**)&result->pEvent);
result->pEvent->SetNotifyWindow((OAHWND)soundwindow, WM_APP, id);
sound->pGraph->QueryInterface(IID_IMediaEventEx, (void**)&sound->pEvent);
sound->pEvent->SetNotifyWindow((OAHWND)soundwindow, WM_APP, id);
sound->pGraph->QueryInterface(IID_IBasicAudio, (void**)&sound->pAudio);
result->pGraph->QueryInterface(IID_IBasicAudio, (void**)&result->pAudio);
result->pControl->RenderFile(path);
result->pControl->Run();
sound->pControl->RenderFile(path);
sound->pControl->Run();
if (loop) {
loopingSounds.push_back(result);
SfallSoundVolume(result, 0, *(DWORD*)_background_volume); // music
loopingSounds.push_back(sound);
SfallSoundVolume(sound, 0, *(DWORD*)_background_volume); // music
} else {
playingSounds.push_back(result);
SfallSoundVolume(result, 1, *(DWORD*)_sndfx_volume);
playingSounds.push_back(sound);
SfallSoundVolume(sound, 1, *(DWORD*)_sndfx_volume);
}
return result;
return sound;
}
static const wchar_t *SoundExtensions[] = { L"mp3", L"wma", L"wav" };
@@ -245,7 +247,7 @@ static bool __cdecl SoundFileLoad(DWORD called, const char* path) {
bool music = (called == 0x45092B); // from gsound_background_play_
if (music && musicLoopPtr != nullptr) {
//if (found && strcmp(path, playingMusicFile) == 0) return true; // don't stop music
StopSfallSound(musicLoopPtr);
StopSfallSound(musicLoopPtr->id);
musicLoopPtr = nullptr;
}
if (!isExist) return false;
@@ -271,18 +273,20 @@ static void __fastcall MakeMusicPath(const char* file) {
SoundFileLoad(0x45092B, pathBuf);
}
void* __stdcall PlaySfallSound(const char* path, bool loop) {
DWORD __stdcall PlaySfallSound(const char* path, bool loop) {
wchar_t buf[256];
mbstowcs_s(0, buf, path, 256);
sDSSound* result = PlayingSound(buf, loop);
return (loop) ? result : 0;
sDSSound* sound = PlayingSound(buf, loop);
return (loop && sound) ? sound->id : 0;
}
void __stdcall StopSfallSound(void* _ptr) {
sDSSound* ptr = (sDSSound*)_ptr;
for (DWORD i = 0; i < loopingSounds.size(); i++) {
if (loopingSounds[i] == ptr) {
FreeSound(ptr);
void __stdcall StopSfallSound(DWORD id) {
if (!id) return;
for (size_t i = 0; i < loopingSounds.size(); i++) {
if (loopingSounds[i]->id == id) {
sDSSound* sound = loopingSounds[i];
sound->pControl->Stop();
FreeSound(sound);
loopingSounds.erase(loopingSounds.begin() + i);
return;
}
@@ -328,6 +332,7 @@ static void __declspec(naked) gmovie_play_hook_stop() {
mov eax, musicLoopPtr;
test eax, eax;
jz skip;
mov eax, [eax]; // musicLoopPtr->id
push ecx;
push edx;
push eax;
+2 -2
View File
@@ -21,6 +21,6 @@
void SoundInit();
void SoundExit();
void* __stdcall PlaySfallSound(const char* path, bool loop);
void __stdcall StopSfallSound(void* ptr);
DWORD __stdcall PlaySfallSound(const char* path, bool loop);
void __stdcall StopSfallSound(DWORD id);
void WipeSounds();