
Originally Posted by
hinnie
This is my playsound hook:
Code:
// Funtion Typedefs
typedef void(__stdcall *PlaySoundFn)(const char* sound);
Code:
// Function Pointers to the originals
PlaySoundFn oPlaySound;
Code:
// Hook function prototypes
void __stdcall Hooked_PlaySound(const char* sound);
Code:
// VMT Managers
namespace Hooks
{
Utilities::Memory::VMTManager VMTPlaySound;
};
In hooks.h:
Code:
extern Utilities::Memory::VMTManager VMTPlaySound;
Code:
void Hooks::Initialise()
{
VMTPlaySound.Initialise((DWORD*)Interfaces::Surface);
oPlaySound = (PlaySoundFn)VMTPlaySound.HookMethod((DWORD)&Hooked_PlaySound, 82);
}
In interfaces.cpp:
Code:
Surface = (ISurface*)VGUISurfaceFactory(VGUISurfaceInterfaceName, NULL);
Code:
char* VGUISurfaceInterfaceName = (char*)Utilities::Memory::FindTextPattern("vguimatsurface.dll", "VGUI_Surface0");
Interfaces.h:
Code:
extern ISurface* Surface;
The actual hook:
Code:
void __stdcall Hooked_PlaySound(const char* sound)
{
oPlaySound(sound);
if (strstr(sound, "UI/competitive_accept_beep.wav"))
{
if (Menu::Window.MiscTab.OtherAutoAccept.GetState())
{
DWORD dwIsReady = (Utilities::Memory::FindPatternv2("client.dll", "55 8B EC 83 E4 F8 83 EC 08 56 8B 35 ? ? ? ? 57 8B 8E"));
reinterpret_cast<void(*)()>(dwIsReady)();
}
}
}
Should work ^^
I've never hooked PlaySound but
Code:
VMTPlaySound.Initialise((DWORD*)Interfaces::Surface);
is a bad name since PlaySound is the 82'th virtual function in the Surface, call it VMTSurface instead.
EDIT:
PlaySound is a thiscall function. But you can define your hooked function as an stdcall:
Code:
void __stdcall Hooked_PlaySound(const char* pStrSound)
Define the PlaySoundFn like this
Code:
typedef void(__thiscall* PlaySoundFn)(void*, const char*);
Get the ecx register in your hook like this
Code:
void* pThis;
__asm pThis, ecx
Call the original PlaySound with pThis as the this pointer
Code:
oPlaySound(pThis, pStrSound);
Worked for me.