How do I use WriteProcessMemory
to change ammo of my current ammo address? I know how to read it I just don't know how to write it. Is SetAmmo . I thought i'm doing everything wright?
Code:
#include <iostream>
#include <math.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
DWORD pid;
DWORD Ammo = 0x07823C5EC;
int MyAmmo;
int SetAmmo = 1;
int main(){
HWND hwnd = FindWindowA(0, ("Garry's Mod"));
GetWindowThreadProcessId(hwnd, &pid);
HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
ReadProcessMemory(pHandle, (LPVOID)Ammo, &MyAmmo, sizeof(MyAmmo), 0);
cout<<"Current Ammo = "<<MyAmmo<<endl;
WriteProcessMemory(pHandle, (LPVOID)Ammo, &SetAmmo, sizeof(SetAmmo), 0);
system("Pause");
return 0;
}
you open the process with read access:
HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
try:
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);