ReadProcessMemory into an array then use this:
Code:
//credits to Dominik & Patrick
bool bDataCompare( const unsigned char* pData, const unsigned char* bMask, const char* szMask );
unsigned long dwFindPattern( unsigned char *bMask,char * szMask, unsigned long dw_Address = dwStartAddress, unsigned long dw_Len = dwLen );
bool bDataCompare(const unsigned char* pData, const unsigned char* bMask, const char* szMask)
{
for(;*szMask;++szMask,++pData,++bMask)
if(*szMask=='x' && *pData!=*bMask )
return false;
return (*szMask) == 0;
}
unsigned long dwFindPattern( unsigned char *bMask,char * szMask, unsigned long dw_Address = 0x00401000, unsigned long dw_Len = 0x00861FFF )
{
for(unsigned long i=0; i < dw_Len; i++)
if( bDataCompare( (unsigned char*)( dw_Address+i ),bMask,szMask) )
return (unsigned long)(dw_Address+i);
return 0;
}
Substract the array start address off the address it returns, then add the start address of where you started reading and you'll have the offset in the games memory.
Code usage:
Code:
char lolwat[512] = {0,};
ReadProcMemory(0x1337, lolwat, 512);//i know this one is wrong, but you get the picture >.>
unsigned long foundAddy = dwFindPattern( "\x15\x20\x30\x40\x90","x?x?x", &lolwat, 512 );
foundAddy -= &lolwat;
foundAddy += 0x1337;