I'm trying to create a trainer for Icy Tower 1.4 for educational purposes.
I wrote a function that shorten the WriteProcessMemory function like that:
void WPM(HWND hWnd,int address,byte data[])
{
DWORD proc_id;
GetWindowThreadProcessId(hWnd, &proc_id);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
if(!hProcess)
return;
DWORD dataSize = sizeof(data);
WriteProcessMemory(hProcess,(LPVOID)address,&data,dataSize,NULL);
CloseHandle(hProcess);
}
and that's the function that should stop the Icy Tower Clock:
void ClockHack(int status)
{
if(status==1)//enable
{
//crashes the game
byte data[]={0xc7,0x05,0x04,0x11,0x45,0x00,0x00,0x00,0x00,0x00};
WPM(FindIcyTower(),0x00415E19,data);
}
else if(status==0)//disable
{
byte data[]={0xA3,0x04,0x11,0x45,0x00};
}
}
in the else statement there's the orginal AOB of the Opcode. When I call the ClockHack function with the status parameter set to 1, the game crashes.
In Cheat Engine I wrote for this a script, that dosen't exactly write to the same address because I did Code Cave and it works great.
Someone knows why? Thank you.
By the way: it is for educational purposes only.