如何使用WriteProcessMemory
更改我当前弹药地址的弹药?我知道怎么读,只是不知道怎么写。是 SetAmmo 。我以为我做的一切都是对的?
代码:
#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;
}