My very small hack I've made is crashing my game and I don't know why, all I wanted to do was keep the ammo at 42 (favorite number) and not let it decrease. but whenever I start the exe the game crashes... should I make it as a dll and inject it instead? this is the error I get upon starting the exe "win32 exception 0x0000005 [0x36]"
and here is my code
#include "stdafx.h"
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
int main(void)
{
int nVal = 42;
HWND hWnd = FindWindowA(0, "AssaultCube");
if (hWnd == 0)
{
cerr << "Could not find window" << endl;
}
else
{
BYTE data[] = { 0x0, 0x14, 0x384, 0x0 };
DWORD pId;
GetWindowThreadProcessId(hWnd, &pId);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, pId);
if (!hProc)
{
cerr << "Process can't open.." << endl;
}
else
{
int stat = WriteProcessMemory(hProc, (LPVOID)0x005100F8, &nVal, (DWORD)sizeof(nVal), NULL);
if (stat < 42)
{
clog << "Activated" << endl;
}
else
{
cerr << "Not applied" << endl;
}
CloseHandle(hProc);
}
}
system("pause");
return 0;
}