Thanks everyone for posting! Sorry it took me a few days to reply.
Jabberwo0ck: Yes the memory address is the right one, I used an online list of memory addresses. I used your error function, the error it gave was "access denied" which was what I thought it probably was.
abuckau907: Running as admin seemed to fix it but I really wanted to be able to run the hack with a limited account, I could edit the values using cheat engine fine but not with my hack. I prefer using c style strings instead out cout, I find it cleaner and easier to organize data.
[MPGH]Biesi: I have seen some people using debug privileges but I could never get it to work. You were right about adjusting the access rights.
I got it working, I changed the access rights to: PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION
and now it seems to work great so thanks everyone!
Here's the code:
Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>
int newdata = 1000;
void ShowError(DWORD dwErrorCode)
{
TCHAR* lpMessageBuffer;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (TCHAR*)&lpMessageBuffer, 0, NULL);
MessageBox(HWND_DESKTOP, lpMessageBuffer, NULL, MB_OK | MB_ICONINFORMATION);
LocalFree(lpMessageBuffer);
}
int main()
{
HWND hWnd = FindWindow(0, "GTA:SA:MP");
if(hWnd == 0)
{
ShowError(GetLastError());
}
else
{
DWORD ProcessID;
GetWindowThreadProcessId(hWnd, &ProcessID);
HANDLE handleprocess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, ProcessID);
if(!handleprocess)
{
ShowError(GetLastError());
}
else{
int hack = WriteProcessMemory(handleprocess, (LPVOID)0xB7CE50, &newdata, (DWORD)sizeof(newdata), NULL);
if(hack > 0){
printf("success!");
}
else{
ShowError(GetLastError());
}
}
CloseHandle(handleprocess);
}
getchar();
return 0;
}