Hello, I need help with the following code:
#include <windows.h>
#include <tlhelp32.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
bool ChangeMemVal(const char * ProcessName, LPVOID MemAddress, int NewVal, int size);
int main()
{
printf("=== Pinball Trainer Example. Made by Hawkpath ===\n\n");
if(ChangeMemVal("pinball.exe", (void*) 0x000F4240, 1000000, 4))
printf("The score has been edited successfully.\n");
else
printf("An error occured while attempting edit the score.\n");
system("PAUSE");
return 0;
}
/* This function modifys a memory address according to its arguments.
Arguments :
ProcessName - the process we want to modify
MemAddress - the memory address we want to modify
NewVal - the value we want to change the memory address to
size - the size of the memory address
Returns :
the success of the edit.
*/
bool ChangeMemVal(const char * ProcessName, LPVOID MemAddress, int NewVal, int size)
{
HANDLE hProcessSnap;
HANDLE hProcess = NULL;
PROCESSENTRY32 pe32;
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
pe32.dwSize = sizeof( PROCESSENTRY32 );
Process32First(hProcessSnap, &pe32);
do
{
if(!strcmp(pe32.szExeFile, ProcessName))
{
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
break;
}
}
while(Process32Next(hProcessSnap, &pe32));
CloseHandle( hProcessSnap );
if(hProcess != NULL)
{
WriteProcessMemory(hProcess, MemAddress, &NewVal, size, NULL); // write the value
CloseHandle(hProcess);
return true;
}
return 0;
}
The program runs, and the window says: Score edited successfully, but the score stays the same.
Thank you!