
-----------------------------------
zerocoolminja
Wed Aug 03, 2011 8:26 am

findpattern help
-----------------------------------
I want to build extended find pattern for modern warfare 2 for finding offsets... I have this code and "variable"_t make me a problem...I do not know how to make the prints as clientinfo, CG, CGS and centity every time I start the program...  refdef is static,does not change... clientinfo,cg,cgs and centity is change every time I start play...can anyone help me... :/
#include 
#include 		
#include 
#include 

HANDLE iw4mp = GetCurrentProcess();

int centity_addy = -1;
int clientinfo_addy = -1;
int cg_addy = -1;
int cgs_addy = -1;

clientinfo_t * clientinfo; // = (clientinfo_t*) 0x8EB248;
centity_t * cg_entities; // = (centity_t*) 0x8F7A78;
refdef_t * refdef = (refdef_t*) 0x85EFB0;
cg_t * cg; // = (cg_t*) 0x7F493C;
cgs_t * cgs; // = (cgs_t*) 0x7F0C78;

bool ReadaIW()
{
	//get clientinfo address
	int tmppat = FindPattern(0x0042A000, 0x2000, "\x69\xC9\x2C\x05\x00\x00\x56\x8B\xB1", "XXXXXXXXX");
	if (tmppat == -1) { return false; }
	ReadProcessMemory(iw4mp, (PVOID)tmppat, &clientinfo_addy, 4, NULL);
	if (clientinfo_addy == -1) { return false; }
	clientinfo = (clientinfo_t*) clientinfo_addy-0x1C;

	//get cgs address
	tmppat = FindPattern(0x004C4000, 0x2000, "\x68\xA4\x3B\x00\x00\x33\xFF\x57\x68", "XXXXXXXXX");
	if (tmppat == -1) { return false; }
	ReadProcessMemory(iw4mp, (PVOID)tmppat, &cgs_addy, 4, NULL);
	if (cgs_addy == -1) { return false; }
	cgs = (cgs_t*) cgs_addy;

	//get cg address
	tmppat = FindPattern(0x004C4000, 0x2000, "\x68\x30\xD7\x0F\x00\x57\x68", "XXXXXXX");
	if (tmppat == -1) { return false; }
	ReadProcessMemory(iw4mp, (PVOID)tmppat, &cg_addy, 4, NULL);
	if (cg_addy == -1) { return false; }
	cg = (cg_t*) cg_addy;

	//get centity address
	tmppat = FindPattern(0x004C4000, 0x2000, "\x68\x00\x20\x10\x00\x81\xC1", "xxxxxxx");
	if (tmppat == -1) { return false; }
	ReadProcessMemory(iw4mp, (PVOID)tmppat, &centity_addy, 4, NULL);
	if (centity_addy == -1) { return false; }
	cg_entities = (centity_t*) centity_addy;

	return true;
}

int FindPattern(int start_offset, int size, const char * pattern, const char * mask)
{
	int pos = 0;

	for (int retAddress = start_offset; retAddress < start_offset + size; retAddress++)
	{
		if (*(const char*)retAddress == pattern[pos] || mask[pos] == '?')
		{
			if (mask[pos+1] == '\0')
				return retAddress+1;
			pos++;
		}
		else
			pos = 0;
	}

	return -1;
}
