diff --git a/Plugins/CaptionMod/enginedef.h b/Plugins/CaptionMod/enginedef.h index cc2bb02e..bb01a794 100644 --- a/Plugins/CaptionMod/enginedef.h +++ b/Plugins/CaptionMod/enginedef.h @@ -6,15 +6,15 @@ #define CVOXFILESENTENCEMAX 1536 -#define SND_VOLUME (1<<0) // a byte -#define SND_ATTENUATION (1<<1) // a byte -#define SND_LARGE_INDEX (1<<2) // a long -#define SND_PITCH (1<<3) -#define SND_SENTENCE (1<<4) -#define SND_STOP (1<<5) -#define SND_CHANGE_VOL (1<<6) -#define SND_CHANGE_PITCH (1<<7) -#define SND_SPAWNING (1<<8) +#define SND_VOLUME (1<<0) // a byte 1 +#define SND_ATTENUATION (1<<1) // a byte 2 +#define SND_LARGE_INDEX (1<<2) // a long 4 +#define SND_PITCH (1<<3) //8 +#define SND_SENTENCE (1<<4) //0x10 +#define SND_STOP (1<<5) //0x20 +#define SND_CHANGE_VOL (1<<6) //0x40 +#define SND_CHANGE_PITCH (1<<7) //0x80 +#define SND_SPAWNING (1<<8) //0x100 #define MAX_QPATH 64 // max length of a quake game pathname diff --git a/Plugins/CaptionMod/exportfuncs.cpp b/Plugins/CaptionMod/exportfuncs.cpp index 6ce6503c..6e6f591d 100644 --- a/Plugins/CaptionMod/exportfuncs.cpp +++ b/Plugins/CaptionMod/exportfuncs.cpp @@ -12,7 +12,7 @@ #include "DpiManager.h" #include -cl_enginefunc_t gEngfuncs; +cl_enginefunc_t gEngfuncs = { 0 }; //Legacy MetaAudio cvar_t *al_enable = NULL; @@ -41,6 +41,11 @@ void *gHud = NULL; HWND g_MainWnd = NULL; WNDPROC g_MainWndProc = NULL; +cl_entity_t* EngineGetViewEntity(void) +{ + return gEngfuncs.GetEntityByIndex((*cl_viewentity)); +} + #if 0 void SDL_GetWindowSize(void* window, int* w, int* h) { @@ -240,40 +245,6 @@ void Cap_Reload_f(void) } } -void SvClient_StartWave(const char *name, float duration) -{ - if (!g_pViewPort) - return; - - auto pDict = g_pViewPort->FindDictionary(name, DICT_SOUND); - - if (cap_debug && cap_debug->value) - { - gEngfuncs.Con_Printf(pDict ? "CaptionMod: Sound [%s] found.\n" : "CaptionMod: Sound [%s] not found.\n", name); - } - - if (!pDict) - return; - - //TODO: avol and distance check - - g_pViewPort->StartSubtitle(pDict, duration); -} - -int __fastcall ScClient_FindSoundEx(void *pthis, int, const char *sound) -{ - auto result = gPrivateFuncs.ScClient_FindSoundEx(pthis, 0, sound); - - if (result) - { - int duration = 0; - gPrivateFuncs.FMOD_Sound_getLength(result, &duration, 1); - SvClient_StartWave(sound, (float)duration / 1000.0f); - } - - return result; -} - void HUD_Init(void) { gExportfuncs.HUD_Init(); @@ -306,15 +277,6 @@ void HUD_Init(void) gPrivateFuncs.MessageMode_f = g_pMetaHookAPI->HookCmd("messagemode", MessageMode_f); gPrivateFuncs.MessageMode2_f = g_pMetaHookAPI->HookCmd("messagemode2", MessageMode2_f); - if (g_bIsSvenCoop) - { - gPrivateFuncs.fmodex = GetModuleHandleA("fmodex.dll"); - Sig_FuncNotFound(fmodex); - - gPrivateFuncs.FMOD_Sound_getLength = (decltype(gPrivateFuncs.FMOD_Sound_getLength))GetProcAddress(gPrivateFuncs.fmodex, "?getLength@Sound@FMOD@@QAG?AW4FMOD_RESULT@@PAII@Z"); - Sig_FuncNotFound(FMOD_Sound_getLength); - } - gEngfuncs.pfnRegisterVariable("cap_lang", m_szCurrentLanguage, FCVAR_CLIENTDLL | FCVAR_USERINFO); } @@ -413,17 +375,6 @@ void S_StartWave(sfx_t *sfx, float distance, float avol) g_pViewPort->StartSubtitle(pDict, duration); } -void S_AddSoundDuration(sfx_t* sfx, float &duration) -{ - //Get duration for zero-duration - float flDuration = S_GetDuration(sfx); - - if (flDuration > 0) - { - duration = flDuration; - } -} - static char szsentences[] = "sound/sentences.txt"; static char voxperiod[] = "_period"; static char voxcomma[] = "_comma"; @@ -763,15 +714,13 @@ bool S_StartSentence(const char *name, float distance, float avol) return true; } -//2015-11-26 fixed, to support !SENTENCE and #SENTENCE -//2015-11-26 added, support added up the duration of sound for zero-duration sentences -void S_StartDynamicSound(int entnum, int entchannel, sfx_t *sfx, float *origin, float fvol, float attenuation, int flags, int pitch) +void S_StartSoundTemplate(int entnum, int entchannel, sfx_t* sfx, float* origin, float fvol, float attenuation, int flags, int pitch) { bool ignore = false; float distance = 0; float avol = 1; - if(sfx) + if (sfx) { if (flags & (SND_STOP | SND_CHANGE_VOL | SND_CHANGE_PITCH)) { @@ -780,18 +729,20 @@ void S_StartDynamicSound(int entnum, int entchannel, sfx_t *sfx, float *origin, if (!ignore) { - auto level = gEngfuncs.pfnGetLevelName(); - if (level[0]) + auto szLevelName = gEngfuncs.pfnGetLevelName(); + + if (szLevelName[0]) { if (origin && !(origin[0] == 0 && origin[1] == 0 && origin[2] == 0) && attenuation > 0 && EngineGetViewEntity()) { - float localorg[3]; - VectorCopy(EngineGetViewEntity()->origin, localorg); + float vecLocalOrigin[3]; + VectorCopy(EngineGetViewEntity()->origin, vecLocalOrigin); + + float vecDirection[3]; + VectorSubtract(origin, vecLocalOrigin, vecDirection); - float dir[3]; - VectorSubtract(origin, localorg, dir); + distance = VectorLength(vecDirection); - distance = VectorLength(dir); avol = fvol * (1.0f - distance * (attenuation / 1000.0f)); if (avol < 0) avol = 0; @@ -820,77 +771,249 @@ void S_StartDynamicSound(int entnum, int entchannel, sfx_t *sfx, float *origin, S_StartWave(sfx, distance, avol); } } +} +void S_StartDynamicSound(int entnum, int entchannel, sfx_t *sfx, float *origin, float fvol, float attenuation, int flags, int pitch) +{ + S_StartSoundTemplate(entnum, entchannel, sfx, origin, fvol, attenuation, flags, pitch); gPrivateFuncs.S_StartDynamicSound(entnum, entchannel, sfx, origin, fvol, attenuation, flags, pitch); } -//2015-11-26 fixed, to support !SENTENCE and #SENTENCE -//2015-11-26 added, support added up the duration of sound for zero-duration sentences void S_StartStaticSound(int entnum, int entchannel, sfx_t *sfx, float *origin, float fvol, float attenuation, int flags, int pitch) { - bool ignore = false; - float distance = 0; - float avol = 1; + S_StartSoundTemplate(entnum, entchannel, sfx, origin, fvol, attenuation, flags, pitch); + gPrivateFuncs.S_StartStaticSound(entnum, entchannel, sfx, origin, fvol, attenuation, flags, pitch); +} + +sfx_t *S_FindName(char *name, int *pfInCache) +{ + return gPrivateFuncs.S_FindName(name, pfInCache);; +} + +//Sven Co-op client.dll + +static bool g_bPlayingFMODSound = false; +static bool g_bPlayedFMODSound = false; +static int g_iCurrentPlayingFMODSoundLengthMs = 0; + +bool ScClient_StartSentence(const char* name, float distance, float avol) +{ + if (!g_pViewPort) + return false; + + auto pDict = g_pViewPort->FindDictionary(name, DICT_SENTENCE); - if(sfx) + if (!pDict) { - if (flags & (SND_STOP | SND_CHANGE_VOL | SND_CHANGE_PITCH)) + //skip "!" and "#" + pDict = g_pViewPort->FindDictionary(name + 1); + } + + if (cap_debug && cap_debug->value) + { + if (pDict) { - ignore = true; + gEngfuncs.Con_Printf("CaptionMod: SENTENCE [%s] found. dist: %.2f, avol: %.2f\n", name, distance, avol); } + else + { + gEngfuncs.Con_Printf("CaptionMod: SENTENCE [%s] not found.\n", name); + } + } - if (!ignore) + if (!pDict) + { + return false; + } + + if (!pDict->m_bIgnoreDistanceLimit && cap_max_distance && cap_max_distance->value > 0 && distance > cap_max_distance->value) + { + return false; + } + + if (!pDict->m_bIgnoreVolumeLimit && cap_min_avol && cap_min_avol->value > 0 && avol < cap_min_avol->value) + { + return false; + } + + float duration = 0; + + if (pDict->m_bOverrideDuration) + { + duration = pDict->m_flDuration; + } + else + { +#if 0//TODO... + ScClient_LoadSentence(name + 1, [&duration](sfx_t* sfx) { + + duration += S_GetDuration(sfx); + + }); +#endif + } + + g_pViewPort->StartSubtitle(pDict, duration); + + return true; +} + +void ScClient_StartWave(const char* name, float distance, float avol, int ms_duration) +{ + if (!g_pViewPort) + return; + + if (!Q_strnicmp(name, "sound/", 6)) + name += 6; + else if (!Q_strnicmp(name + 1, "sound/", 6)) + name += 7; + + auto pDict = g_pViewPort->FindDictionary(name, DICT_SOUND); + + if (cap_debug && cap_debug->value) + { + if (pDict) + { + gEngfuncs.Con_Printf("CaptionMod: Sound [%s] found. dist: %.2f, avol: %.2f\n", name, distance, avol); + } + else { - auto level = gEngfuncs.pfnGetLevelName(); - if (level[0]) + gEngfuncs.Con_Printf("CaptionMod: Sound [%s] not found.\n", name); + } + } + + if (!pDict) + { + return; + } + + if (!pDict->m_bIgnoreDistanceLimit && cap_max_distance && cap_max_distance->value > 0 && distance > cap_max_distance->value) + { + return; + } + + if (!pDict->m_bIgnoreVolumeLimit && cap_min_avol && cap_min_avol->value > 0 && avol < cap_min_avol->value) + { + return; + } + + float duration; + + if (pDict->m_bOverrideDuration) + { + duration = pDict->m_flDuration; + } + else + { + duration = ms_duration / 1000.0f; + } + + g_pViewPort->StartSubtitle(pDict, duration); +} + +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) +{ + g_bPlayingFMODSound = true; + g_iCurrentPlayingFMODSoundLengthMs = 0; + + gPrivateFuncs.ScClient_SoundEngine_PlayFMODSound(pSoundEngine, 0, flags, entindex, origin, channel, name, fvol, attenuation, extraflags, pitch, sentenceIndex, soundLength); + + if (g_bPlayedFMODSound) + { + if (name) + { + bool ignore = false; + float distance = 0; + float avol = 1; + + if (flags & (SND_STOP | SND_CHANGE_VOL | SND_CHANGE_PITCH)) { - if (origin && !(origin[0] == 0 && origin[1] == 0 && origin[2] == 0) && attenuation > 0 && EngineGetViewEntity()) + ignore = true; + } + + if (!ignore) + { + auto szLevelName = gEngfuncs.pfnGetLevelName(); + + if (szLevelName[0]) { - float localorg[3]; - VectorCopy(EngineGetViewEntity()->origin, localorg); + if (origin && !(origin[0] == 0 && origin[1] == 0 && origin[2] == 0) && attenuation > 0 && EngineGetViewEntity()) + { + float vecLocalOrigin[3]; + VectorCopy(EngineGetViewEntity()->origin, vecLocalOrigin); - float dir[3]; - VectorSubtract(origin, localorg, dir); + float vecDirection[3]; + VectorSubtract(origin, vecLocalOrigin, vecDirection); - distance = VectorLength(dir); + distance = VectorLength(vecDirection); - avol = fvol * (1.0f - distance * (attenuation / 1000.0f)); - if (avol < 0) - avol = 0; + avol = fvol * (1.0f - distance * (attenuation / 1000.0f)); + if (avol < 0) + avol = 0; + } } } - } - if (!ignore) - { - if (sfx->name[0] == '!' || sfx->name[0] == '#') + if (!ignore) { - if (!S_StartSentence(sfx->name, distance, avol)) + if (name[0] == '!' || name[0] == '#') { - S_LoadSentence(sfx->name + 1, [distance, avol](sfx_t* sfx_sentence) { - - S_StartWave(sfx_sentence, distance, avol); + if (!ScClient_StartSentence(name, distance, avol)) + { - }); + } + ignore = true; } - ignore = true; } - } - if (!ignore) + if (!ignore) + { + ScClient_StartWave(name, distance, avol, g_iCurrentPlayingFMODSoundLengthMs); + } + } + else { - S_StartWave(sfx, distance, avol); + gEngfuncs.Con_DPrintf("ScClient_SoundEngine_PlayFMODSound: sentenceIndex %d\n", sentenceIndex); } } - gPrivateFuncs.S_StartStaticSound(entnum, entchannel, sfx, origin, fvol, attenuation, flags, pitch); + g_bPlayingFMODSound = false; + g_bPlayedFMODSound = false; + g_iCurrentPlayingFMODSoundLengthMs = 0; } -sfx_t *S_FindName(char *name, int *pfInCache) +int __stdcall FMOD_System_playSound(void* FMOD_System, int channelid, void* FMOD_Sound, bool paused, void** FMOD_Channel) { - return gPrivateFuncs.S_FindName(name, pfInCache);; + if (g_bPlayingFMODSound) + { + int duration = 0; + gPrivateFuncs.FMOD_Sound_getLength(FMOD_Sound, &duration, 1); + g_iCurrentPlayingFMODSoundLengthMs = duration; + g_bPlayedFMODSound = true; + } + + return gPrivateFuncs.FMOD_System_playSound(FMOD_System, channelid, FMOD_Sound, paused, FMOD_Channel); } + +#if 0 +int __fastcall ScClient_FindSoundEx(void* pthis, int, const char* sound) +{ + auto result = gPrivateFuncs.ScClient_FindSoundEx(pthis, 0, sound); + + if (result) + { + int duration = 0; + gPrivateFuncs.FMOD_Sound_getLength(result, &duration, 1); + SvClient_StartWave(sound, (float)duration / 1000.0f); + } + + return result; +} +#endif + +//Misc + IBaseInterface *NewCreateInterface(const char *pName, int *pReturnCode) { auto pfnCreateInterface = (decltype(NewCreateInterface) *)Sys_GetFactoryThis(); diff --git a/Plugins/CaptionMod/exportfuncs.h b/Plugins/CaptionMod/exportfuncs.h index 1ef73b1c..2e5d0b40 100644 --- a/Plugins/CaptionMod/exportfuncs.h +++ b/Plugins/CaptionMod/exportfuncs.h @@ -48,7 +48,10 @@ void Cap_Version_f(void); LRESULT WINAPI VID_MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); -int __fastcall ScClient_FindSoundEx(void* pthis, int, const char *sound); +//int __fastcall ScClient_FindSoundEx(void* pthis, int, const char *sound); + +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); +int __stdcall FMOD_System_playSound(void* FMOD_System, int channelid, void* FMOD_Sound, bool paused, void** FMOD_Channel); void __fastcall WeaponsResource_SelectSlot(void *pthis, int, int iSlot, int fAdvance, int iDirection); void VGuiWrap2_Paint(void); diff --git a/Plugins/CaptionMod/plugins.cpp b/Plugins/CaptionMod/plugins.cpp index 5ef6537d..fc35af0f 100644 --- a/Plugins/CaptionMod/plugins.cpp +++ b/Plugins/CaptionMod/plugins.cpp @@ -49,6 +49,7 @@ void IPluginsV4::Init(metahook_api_t *pAPI, mh_interface_t *pInterface, mh_engin void IPluginsV4::Shutdown(void) { + g_pMetaHookAPI->UnregisterLoadDllNotificationCallback(DllLoadNotification); } void IPluginsV4::LoadEngine(cl_enginefunc_t *pEngfuncs) @@ -91,6 +92,8 @@ void IPluginsV4::LoadEngine(cl_enginefunc_t *pEngfuncs) BaseUI_InstallHook(); dpimanager()->Init(); + + g_pMetaHookAPI->RegisterLoadDllNotificationCallback(DllLoadNotification); } void IPluginsV4::LoadClient(cl_exportfuncs_t *pExportFunc) diff --git a/Plugins/CaptionMod/privatefuncs.cpp b/Plugins/CaptionMod/privatefuncs.cpp index fb264481..0ac70b6b 100644 --- a/Plugins/CaptionMod/privatefuncs.cpp +++ b/Plugins/CaptionMod/privatefuncs.cpp @@ -69,10 +69,30 @@ private_funcs_t gPrivateFuncs = { 0 }; static hook_t *g_phook_S_FindName = NULL; static hook_t *g_phook_S_StartDynamicSound = NULL; static hook_t *g_phook_S_StartStaticSound = NULL; -static hook_t *g_phook_ScClient_FindSoundEx = NULL; static hook_t *g_phook_pfnTextMessageGet = NULL; static hook_t *g_phook_WeaponsResource_SelectSlot = NULL; -//hook_t *g_phook_FileSystem_SetGameDirectory = NULL; +static hook_t* g_phook_ScClient_SoundEngine_PlayFMODSound = NULL; +static hook_t* g_phook_FMOD_System_playSound = NULL; +//static hook_t *g_phook_FileSystem_SetGameDirectory = NULL; + +static HMODULE g_hFMODEx = NULL; + +void FMOD_InstallHooks(HMODULE fmodex) +{ + gPrivateFuncs.FMOD_Sound_getLength = (decltype(gPrivateFuncs.FMOD_Sound_getLength))GetProcAddress(fmodex, "?getLength@Sound@FMOD@@QAG?AW4FMOD_RESULT@@PAII@Z"); + Sig_FuncNotFound(FMOD_Sound_getLength); + + gPrivateFuncs.FMOD_System_playSound = (decltype(gPrivateFuncs.FMOD_System_playSound))GetProcAddress(fmodex, "?playSound@System@FMOD@@QAG?AW4FMOD_RESULT@@W4FMOD_CHANNELINDEX@@PAVSound@2@_NPAPAVChannel@2@@Z"); + Sig_FuncNotFound(FMOD_System_playSound); + + //g_phook_FMOD_System_playSound = g_pMetaHookAPI->IATHook(g_hClientDll, "fmodex.dll", "?playSound@System@FMOD@@QAG?AW4FMOD_RESULT@@W4FMOD_CHANNELINDEX@@PAVSound@2@_NPAPAVChannel@2@@Z", FMOD_System_playSound, NULL); + Install_InlineHook(FMOD_System_playSound); +} + +void FMOD_UninstallHooks(HMODULE fmodex) +{ + Uninstall_Hook(FMOD_System_playSound); +} PVOID VGUIClient001_CreateInterface(HINTERFACEMODULE hModule) { @@ -1359,12 +1379,36 @@ void Engine_FillAddress(void) void Client_FillAddress(void) { + ULONG ClientTextSize = 0; + auto ClientTextBase = g_pMetaHookAPI->GetSectionByName(g_dwClientBase, ".text\0\0\0", &ClientTextSize); + + if (!ClientTextBase) + { + g_pMetaHookAPI->SysError("Failed to locate section \".text\" in client.dll!"); + } + + ULONG ClientDataSize = 0; + auto ClientDataBase = g_pMetaHookAPI->GetSectionByName(g_dwClientBase, ".data\0\0\0", &ClientDataSize); + + ULONG ClientRDataSize = 0; + auto ClientRDataBase = g_pMetaHookAPI->GetSectionByName(g_dwClientBase, ".rdata\0\0", &ClientRDataSize); + auto pfnClientFactory = g_pMetaHookAPI->GetClientFactory(); if (pfnClientFactory && pfnClientFactory("SCClientDLL001", 0)) { g_bIsSvenCoop = true; + if (1) + { + char pattern[] = "\x6A\x00\x50\x6A\xFF\x6A\x08\xE8\x2A\x2A\x2A\x2A\x2A\x2A\xE8"; + auto addr = (PUCHAR)Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern); + Sig_VarNotFound("ScClient_SoundEngine_PlayFMODSound"); + + gPrivateFuncs.ScClient_SoundEngine_PlayFMODSound = (decltype(gPrivateFuncs.ScClient_SoundEngine_PlayFMODSound))GetCallAddress(addr + Sig_Length(pattern) - 1); + } + +#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" { gPrivateFuncs.ScClient_FindSoundEx = (decltype(gPrivateFuncs.ScClient_FindSoundEx)) @@ -1372,18 +1416,19 @@ void Client_FillAddress(void) Sig_FuncNotFound(ScClient_FindSoundEx); } +#endif -#define SC_GETCLIENTCOLOR_SIG "\x8B\x4C\x24\x04\x85\xC9\x2A\x2A\x6B\xC1\x58" + if(1) { - gPrivateFuncs.GetClientColor = (decltype(gPrivateFuncs.GetClientColor)) - g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, SC_GETCLIENTCOLOR_SIG, Sig_Length(SC_GETCLIENTCOLOR_SIG)); - + char pattern[] = "\x8B\x4C\x24\x04\x85\xC9\x2A\x2A\x6B\xC1\x58"; + gPrivateFuncs.GetClientColor = (decltype(gPrivateFuncs.GetClientColor))Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern); Sig_FuncNotFound(GetClientColor); } -#define SC_VIEWPORT_SIG "\x8B\x0D\x2A\x2A\x2A\x2A\x85\xC9\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x84\xC0\x0F" + if(1) { - auto addr = (PUCHAR)g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, SC_VIEWPORT_SIG, Sig_Length(SC_VIEWPORT_SIG)); + char pattern[] = "\x8B\x0D\x2A\x2A\x2A\x2A\x85\xC9\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x84\xC0\x0F"; + auto addr = (PUCHAR)Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern); Sig_AddrNotFound(GameViewport); @@ -1392,9 +1437,10 @@ void Client_FillAddress(void) gPrivateFuncs.GameViewport_AllowedToPrintText = (decltype(gPrivateFuncs.GameViewport_AllowedToPrintText))GetCallAddress(addr + 10); } -#define SC_VIEWPORT_ISSCOREBOARDVISIBLE_SIG "\x8B\x01\x8B\x40\x28\xFF\xE0" + if(1) { - auto addr = (PUCHAR)g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, SC_VIEWPORT_ISSCOREBOARDVISIBLE_SIG, Sig_Length(SC_VIEWPORT_ISSCOREBOARDVISIBLE_SIG)); + char pattern[] = "\x8B\x01\x8B\x40\x28\xFF\xE0"; + auto addr = (PUCHAR)Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern); Sig_AddrNotFound(GameViewport_IsScoreBoardVisible); @@ -1415,18 +1461,19 @@ void Client_FillAddress(void) Sig_FuncNotFound(GameViewport_IsScoreBoardVisible); } -#define SELECTSLOT_STRING_SIG "common/wpn_hudon.wav" + if(1) { - auto addr = (PUCHAR)g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, SELECTSLOT_STRING_SIG, Sig_Length(SELECTSLOT_STRING_SIG)); + char pattern[] = "common/wpn_hudon.wav"; + auto addr = (PUCHAR)Search_Pattern_From_Size(ClientRDataBase, ClientRDataSize, pattern); Sig_AddrNotFound(wpn_hudon_wav_String); - char pattern[] = "\x68\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x83\xC4\x08"; - *(DWORD *)(pattern + 1) = (DWORD)addr; - auto Push_wpn_hudon_Call = g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, pattern, Sig_Length(pattern)); - Sig_VarNotFound(Push_wpn_hudon_Call); + char pattern2[] = "\x68\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x83\xC4\x08"; + *(DWORD *)(pattern2 + 1) = (DWORD)addr; + auto wpn_hudon_PushString = Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern2); + Sig_VarNotFound(wpn_hudon_PushString); - gPrivateFuncs.WeaponsResource_SelectSlot = (decltype(gPrivateFuncs.WeaponsResource_SelectSlot))g_pMetaHookAPI->ReverseSearchFunctionBeginEx(Push_wpn_hudon_Call, 0x250, [](PUCHAR Candidate) { + gPrivateFuncs.WeaponsResource_SelectSlot = (decltype(gPrivateFuncs.WeaponsResource_SelectSlot))g_pMetaHookAPI->ReverseSearchFunctionBeginEx(wpn_hudon_PushString, 0x250, [](PUCHAR Candidate) { //.text:10054A80 55 push ebp //.text:10054A81 8B EC mov ebp, esp @@ -1446,23 +1493,24 @@ void Client_FillAddress(void) Sig_FuncNotFound(WeaponsResource_SelectSlot); } -#define SC_UPDATECURSORSTATE_SIG "\x8B\x40\x28\xFF\xD0\x84\xC0\x2A\x2A\xC7\x05\x2A\x2A\x2A\x2A\x01\x00\x00\x00" + if(1) { - auto addr = (PUCHAR)g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, SC_UPDATECURSORSTATE_SIG, Sig_Length(SC_UPDATECURSORSTATE_SIG)); + char pattern[] = "\x8B\x40\x28\xFF\xD0\x84\xC0\x2A\x2A\xC7\x05\x2A\x2A\x2A\x2A\x01\x00\x00\x00"; + auto addr = (PUCHAR)Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern); Sig_AddrNotFound(g_iVisibleMouse); g_iVisibleMouse = *(decltype(g_iVisibleMouse) *)(addr + 11); } -#define SC_GETBORDERSIZE_SIG "\xF6\x05\x2A\x2A\x2A\x2A\x20\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8" + if(1) { - auto addr = (PUCHAR)g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, SC_GETBORDERSIZE_SIG, Sig_Length(SC_GETBORDERSIZE_SIG)); + char pattern[] = "\xF6\x05\x2A\x2A\x2A\x2A\x20\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8"; + auto addr = (PUCHAR)Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern); Sig_AddrNotFound(CHud_GetBorderSize); gHud = *(decltype(gHud) *)(addr + 10); - gPrivateFuncs.CHud_GetBorderSize = (decltype(gPrivateFuncs.CHud_GetBorderSize)) - g_pMetaHookAPI->GetNextCallAddr(addr + Sig_Length(SC_GETBORDERSIZE_SIG) - 1, 1); + gPrivateFuncs.CHud_GetBorderSize = (decltype(gPrivateFuncs.CHud_GetBorderSize)) GetCallAddress(addr + Sig_Length(pattern) - 1); } } @@ -1472,23 +1520,24 @@ void Client_FillAddress(void) if (1) { -#define CS_CZ_GETTEXTCOLOR_SIG "\x8B\x44\x24\x04\x83\xE8\x03\x2A\x2A\x48" - gPrivateFuncs.GetTextColor = (decltype(gPrivateFuncs.GetTextColor)) - g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, CS_CZ_GETTEXTCOLOR_SIG, Sig_Length(CS_CZ_GETTEXTCOLOR_SIG)); + char pattern[] = "\x8B\x44\x24\x04\x83\xE8\x03\x2A\x2A\x48"; + gPrivateFuncs.GetTextColor = (decltype(gPrivateFuncs.GetTextColor))Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern); //Sig_FuncNotFound(GetTextColor); } -#define CS_CZ_GETCLIENTCOLOR_SIG "\x0F\xBF\x2A\x2A\x2A\x2A\x2A\x2A\x48\x83\xF8\x03\x77\x2A\xFF\x24" -#define CS_CZ_GETCLIENTCOLOR_SIG_HL25 "\x55\x8B\xEC\x6B\x45\x08\x74\x0F\xBF\x80\x2A\x2A\x2A\x2A\x48\x83\xF8\x03\x77\x23\xFF\x24\x85" +#define CS_CZ_GETCLIENTCOLOR_SIG +#define CS_CZ_GETCLIENTCOLOR_SIG_HL25 if (1) { + char pattern[] = "\x0F\xBF\x2A\x2A\x2A\x2A\x2A\x2A\x48\x83\xF8\x03\x77\x2A\xFF\x24"; + char pattern_HL25[] = "\x55\x8B\xEC\x6B\x45\x08\x74\x0F\xBF\x80\x2A\x2A\x2A\x2A\x48\x83\xF8\x03\x77\x23\xFF\x24\x85"; if (g_iEngineType != ENGINE_GOLDSRC_HL25) { - DWORD addr = (DWORD)g_pMetaHookAPI->SearchPattern(g_dwClientBase, g_dwClientSize, CS_CZ_GETCLIENTCOLOR_SIG, Sig_Length(CS_CZ_GETCLIENTCOLOR_SIG)); + auto addr = (PUCHAR)Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern); if (addr) { - gPrivateFuncs.GetClientColor = (decltype(gPrivateFuncs.GetClientColor))g_pMetaHookAPI->ReverseSearchFunctionBeginEx((PVOID)addr, 0x50, [](PUCHAR Candidate) { + gPrivateFuncs.GetClientColor = (decltype(gPrivateFuncs.GetClientColor))g_pMetaHookAPI->ReverseSearchFunctionBeginEx(addr, 0x50, [](PUCHAR Candidate) { //8B 44 24 04 mov eax, [esp+arg_0] if (Candidate[0] == 0x8B && @@ -1506,12 +1555,7 @@ void Client_FillAddress(void) } else { - gPrivateFuncs.GetClientColor = (decltype(gPrivateFuncs.GetClientColor))g_pMetaHookAPI->SearchPattern( - g_dwClientBase, - g_dwClientSize, - CS_CZ_GETCLIENTCOLOR_SIG_HL25, - Sig_Length(CS_CZ_GETCLIENTCOLOR_SIG_HL25) - ); + gPrivateFuncs.GetClientColor = (decltype(gPrivateFuncs.GetClientColor))Search_Pattern_From_Size(ClientTextBase, ClientTextSize, pattern_HL25); Sig_FuncNotFound(GetClientColor); } @@ -1593,9 +1637,6 @@ void Engine_InstallHooks(void) Install_InlineHook(S_StartDynamicSound); Install_InlineHook(S_StartStaticSound); Install_InlineHook(pfnTextMessageGet); - //Install_InlineHook(FileSystem_SetGameDirectory); - //Install_InlineHook(VGuiWrap2_Paint); - //Install_InlineHook(SDL_GetWindowSize); } void Engine_UninstallHooks(void) @@ -1603,16 +1644,13 @@ void Engine_UninstallHooks(void) Uninstall_Hook(S_StartDynamicSound); Uninstall_Hook(S_StartStaticSound); Uninstall_Hook(pfnTextMessageGet); - //Uninstall_Hook(FileSystem_SetGameDirectory); - //Uninstall_Hook(VGuiWrap2_Paint); - //Uninstall_Hook(SDL_GetWindowSize); } void Client_InstallHooks(void) { - if (gPrivateFuncs.ScClient_FindSoundEx) + if (gPrivateFuncs.ScClient_SoundEngine_PlayFMODSound) { - Install_InlineHook(ScClient_FindSoundEx); + Install_InlineHook(ScClient_SoundEngine_PlayFMODSound); } if (gPrivateFuncs.WeaponsResource_SelectSlot) @@ -1623,11 +1661,26 @@ void Client_InstallHooks(void) void Client_UninstallHooks(void) { - Uninstall_Hook(ScClient_FindSoundEx); + Uninstall_Hook(ScClient_SoundEngine_PlayFMODSound); Uninstall_Hook(WeaponsResource_SelectSlot); } -cl_entity_t *EngineGetViewEntity(void) +void DllLoadNotification(mh_load_dll_notification_context_t* ctx) { - return gEngfuncs.GetEntityByIndex((*cl_viewentity)); -} \ No newline at end of file + if (ctx->flags & LOAD_DLL_NOTIFICATION_IS_LOAD) + { + if (ctx->BaseDllName && ctx->hModule && !_wcsicmp(ctx->BaseDllName, L"fmodex.dll")) + { + g_hFMODEx = ctx->hModule; + FMOD_InstallHooks(ctx->hModule); + } + } + else if (ctx->flags & LOAD_DLL_NOTIFICATION_IS_UNLOAD) + { + if (ctx->hModule == g_hFMODEx) + { + FMOD_UninstallHooks(ctx->hModule); + g_hFMODEx = NULL; + } + } +} diff --git a/Plugins/CaptionMod/privatefuncs.h b/Plugins/CaptionMod/privatefuncs.h index c5866efa..8fa2d153 100644 --- a/Plugins/CaptionMod/privatefuncs.h +++ b/Plugins/CaptionMod/privatefuncs.h @@ -45,12 +45,13 @@ typedef struct //SC ClientDLL - int(__fastcall *ScClient_FindSoundEx)(void *pthis, int, const char *soundName); - + //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); + //FMOD - HMODULE fmodex; - int(__stdcall *FMOD_Sound_getLength)(int a1, void* a2, int a3);//?getLength@Sound@FMOD@@QAG?AW4FMOD_RESULT@@PAII@Z + int(__stdcall*FMOD_Sound_getLength)(void * FMOD_Sound, void* output, int type);//?getLength@Sound@FMOD@@QAG?AW4FMOD_RESULT@@PAII@Z + int(__stdcall*FMOD_System_playSound)(void* FMOD_System, int channelid, void* FMOD_Sound, bool paused, void** FMOD_Channel);//?playSound@System@FMOD@@QAG?AW4FMOD_RESULT@@W4FMOD_CHANNELINDEX@@PAVSound@2@_NPAPAVChannel@2@@Z //ClientDLL @@ -159,4 +160,8 @@ void VGUI1_Shutdown(void); void Surface_InstallHooks(void); void Surface_UninstallHooks(void); void Scheme_InstallHooks(void); -void KeyValuesSystem_InstallHook(void); \ No newline at end of file +void KeyValuesSystem_InstallHook(void); +void FMOD_InstallHooks(HMODULE fmodex); +void FMOD_UninstallHooks(HMODULE fmodex); + +void DllLoadNotification(mh_load_dll_notification_context_t* ctx); diff --git a/Plugins/ThreadGuard/privatehook.cpp b/Plugins/ThreadGuard/privatehook.cpp index df709861..b9875db3 100644 --- a/Plugins/ThreadGuard/privatehook.cpp +++ b/Plugins/ThreadGuard/privatehook.cpp @@ -106,7 +106,7 @@ void ServerBrowser_InstallHook(HMODULE hModule) g_ThreadManager_ServerBrowser->InstallHook(hookflag_CreateThread | hookflag_WaitForSingleObject); } -void ServerBrowser_UnistallHook(HMODULE hModule) +void ServerBrowser_UninstallHook(HMODULE hModule) { if (g_ThreadManager_ServerBrowser) { @@ -146,7 +146,7 @@ void DllLoadNotification(mh_load_dll_notification_context_t* ctx) } else if (g_ThreadManager_ServerBrowser && ctx->hModule == g_ThreadManager_ServerBrowser->GetModule()) { - ServerBrowser_UnistallHook(ctx->hModule); + ServerBrowser_UninstallHook(ctx->hModule); } } } \ No newline at end of file