Skip to content

Commit

Permalink
Add sentence support for Sven Co-op.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 20, 2024
1 parent 59c89e1 commit fa40632
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Plugins/CaptionMod/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ sfx_t *S_FindName(char *name, int *pfInCache)
static bool g_bPlayingFMODSound = false;
static bool g_bPlayedFMODSound = false;
static int g_iCurrentPlayingFMODSoundLengthMs = 0;
static void* g_pFMODSystem = NULL;

bool ScClient_StartSentence(const char* name, float distance, float avol)
{
Expand Down Expand Up @@ -915,6 +916,7 @@ void __fastcall ScClient_SoundEngine_PlayFMODSound(void* pSoundEngine, int, int
{
g_bPlayingFMODSound = true;
g_iCurrentPlayingFMODSoundLengthMs = 0;
g_pFMODSystem = *(void **)((PUCHAR)pSoundEngine + 0x2004);

gPrivateFuncs.ScClient_SoundEngine_PlayFMODSound(pSoundEngine, 0, flags, entindex, origin, channel, name, fvol, attenuation, extraflags, pitch, sentenceIndex, soundLength);

Expand Down Expand Up @@ -954,7 +956,14 @@ void __fastcall ScClient_SoundEngine_PlayFMODSound(void* pSoundEngine, int, int

if (!ignore && !name && sentenceIndex >= 0)
{
//TODO: Sentence support
auto sentenceName = gPrivateFuncs.ScClient_SoundEngine_LookupSoundBySentenceIndex(pSoundEngine, sentenceIndex);

if (sentenceName)
{
ScClient_StartWave(sentenceName, distance, avol, g_iCurrentPlayingFMODSoundLengthMs);

ignore = true;
}
}

if (!ignore && name)
Expand All @@ -970,7 +979,7 @@ void __fastcall ScClient_SoundEngine_PlayFMODSound(void* pSoundEngine, int, int

int __stdcall FMOD_System_playSound(void* FMOD_System, int channelid, void* FMOD_Sound, bool paused, void** FMOD_Channel)
{
if (g_bPlayingFMODSound)
if (g_bPlayingFMODSound && g_pFMODSystem == FMOD_System)
{
int duration = 0;
gPrivateFuncs.FMOD_Sound_getLength(FMOD_Sound, &duration, 1);
Expand Down
9 changes: 9 additions & 0 deletions Plugins/CaptionMod/privatefuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,15 @@ void Client_FillAddress(void)
gPrivateFuncs.ScClient_SoundEngine_PlayFMODSound = (decltype(gPrivateFuncs.ScClient_SoundEngine_PlayFMODSound))GetCallAddress(addr + Sig_Length(pattern) - 1);
}

if (1)
{
char pattern[] = "\x8B\x54\x24\x04\x81\xFA\xFF\x0F\x00\x00\x2A\x2A\x83\x3C\x91\x00\x2A\x2A\x0F\xAE\xE8";
auto addr = (PUCHAR)Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern);
Sig_VarNotFound("ScClient_SoundEngine_LookupSoundBySentenceIndex");

gPrivateFuncs.ScClient_SoundEngine_LookupSoundBySentenceIndex = (decltype(gPrivateFuncs.ScClient_SoundEngine_LookupSoundBySentenceIndex))addr;
}

#if 0
#define SC_FINDSOUND_SIG "\x51\x55\x8B\x6C\x24\x0C\x89\x4C\x24\x04\x85\xED\x0F\x84\x2A\x2A\x2A\x2A\x80\x7D\x00\x00"
{
Expand Down
3 changes: 2 additions & 1 deletion Plugins/CaptionMod/privatefuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ typedef struct

//int(__fastcall *ScClient_FindSoundEx)(void *pthis, int, const char *soundName);
void (__fastcall*ScClient_SoundEngine_PlayFMODSound)(void *pSoundEngine, int, int flags, int entindex, float *origin, int channel, const char *name, float fvol, float attenuation, int extraflags, int pitch, int sentenceIndex, float soundLength);

const char *(__thiscall* ScClient_SoundEngine_LookupSoundBySentenceIndex)(void* pSoundEngine, int sentenceIndex);

//FMOD

int(__stdcall*FMOD_Sound_getLength)(void * FMOD_Sound, void* output, int type);//?getLength@Sound@FMOD@@QAG?AW4FMOD_RESULT@@PAII@Z
Expand Down

0 comments on commit fa40632

Please sign in to comment.