All pastes #2124694 Raw Edit

Something

public text v1 · immutable
#2124694 ·published 2012-03-05 22:23 UTC
rendered paste body
//==============================================================================
#include "Sound Hook.h"
#include "Memory Tools.h"
//==============================================================================

//==============================================================================
DWORD g_dwHW_Base				= 0x01D0D000;
DWORD g_dwHW_Len				= 0x000645a4; 
DWORD g_dwCL_ParseSound_Begin	= NULL;
DWORD g_dwCL_ParseSound_Call	= NULL;
DWORD g_dwCL_ParseSound_End		= NULL;
DWORD g_dwSvc_Table				= NULL;
//==============================================================================
svc_entry_s*					pSvcDispatch;
sound_t							pSound;
//==============================================================================
void S_StartDynamicSound( int entnum, int entchannel, char* sample, float* origin, float volume, float attenuation, int timeofs , int pitch )
{
	(*pSound)(entnum,entchannel,sample,origin,volume,attenuation,timeofs,pitch);
}
//==============================================================================
DWORD dwHook_SvcEntry( DWORD dwBegin,	 // begin of the parser
					   DWORD dwEnd,		 // end of the parser
					   DWORD dwCall,	 // call to the original handler
					   DWORD dwHandler,  // our handler
					   int iPos			 // svc_table element ##x
					 )
{	
	//Make a copy of the original Handler
	DWORD dwMy_Handler			= gMemoryTools.dwCopyRange( dwBegin , dwEnd );
	//Hook Svc_Table ( hw.dll )
	pSvcDispatch[iPos].pfnHandler = (DWORD)dwMy_Handler;
	//Redirect Call
	return gMemoryTools.dwRedirectCall( ( dwMy_Handler + dwCall ), dwHandler );
}
//==============================================================================
void SetupSoundHook( void )
{
	g_dwCL_ParseSound_Begin = gMemoryTools.dwFindPattern( g_dwHW_Base,g_dwHW_Len,(BYTE*)"\x83\xEC\x68\x53\x55\x56\x57\x68\x00\x00\x00\x00\xE8","xxxxxxxx????x");
	g_dwCL_ParseSound_Call  = gMemoryTools.dwFindPattern( g_dwHW_Base,g_dwHW_Len,(BYTE*)"\x50\x57\xE8\x00\x00\x00\x00\x83\xC4\x20\x5F\x5E\x5D\x5B\x83\xC4\x68\xC3","xxx????xxxxxxxxxxx");
	g_dwCL_ParseSound_End	= gMemoryTools.dwFindPattern( g_dwHW_Base,g_dwHW_Len,(BYTE*)"\x50\x57\x68\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x83\xC4\x0C\x5F\x5E\x5D\x5B\x83\xC4\x68\xC3","xxx????x????xxxxxxxxxxx");
	g_dwSvc_Table			= gMemoryTools.dwFindPattern( g_dwHW_Base,g_dwHW_Len,(BYTE*)"\x51\x53\x56\x57\x68\xFF\xFF\xFF\xFF\x33\xDB\xE8\xFF\xFF\xFF\xFF\x83\xC4\x04\x33\xF6\xBF","xxxxx????xxx????xxxxxx");

	//correct vals
	g_dwSvc_Table			 += 0x15;
	g_dwCL_ParseSound_End	 += 0x16;
	g_dwCL_ParseSound_Call	 += 2;
	g_dwCL_ParseSound_Call	 -= g_dwCL_ParseSound_Begin;
	//set locations
	pSvcDispatch			  = (svc_entry_s*)(*(DWORD*)(g_dwSvc_Table + 1 ) - 4 );

	pSound = (sound_t)dwHook_SvcEntry( g_dwCL_ParseSound_Begin ,g_dwCL_ParseSound_End , g_dwCL_ParseSound_Call , (DWORD)S_StartDynamicSound, 6 );
}
//==============================================================================


#ifndef _SOUNDHOOK_H_
#define _SOUNDHOOK_H_

#include "Include.h"

//==============================================================================
void S_StartDynamicSound( int entnum, int entchannel, char* sample, float* origin, float volume, float attenuation, int timeofs , int pitch );
void SetupSoundHook( void );
typedef void   (*sound_t)(int,int,char*,float*,float,float,int,int);
//==============================================================================
typedef struct svc_entry_s
{
	DWORD dwId;			// +0 - id :) should be unique
	char  *szName;		// +4 - pointer to the name string
	DWORD pfnHandler;	// +C - the parser itself
};
//==============================================================================

#endif


Call SetupSoundHook in your Init, sound code goes in S_StartDyanmicSound ( Pre original call ).