When I'm pressing F1 game Falls down.
When I'm pressing F2 Health changes and everything is ok.
The Debugger shows that it is falling when we are writing to memory ( WriteProcessMemory(hProcHandle,(BYTE*)AddressToWrite,&AmmoValue,sizeof(AmmoValue),NULL); )
Here is the code

When I'm pressing F2 Health changes and everything is ok.
The Debugger shows that it is falling when we are writing to memory ( WriteProcessMemory(hProcHandle,(BYTE*)AddressToWrite,&AmmoValue,sizeof(AmmoValue),NULL); )
Here is the code
C++:
#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>
DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offset[], DWORD BaseAddres);
void WriteTomemory(HANDLE hProcHandle);
std::string GameName = "AssaultCube";
LPCSTR LGameWindow = "AssaultCube";
std::string GameStatus;
bool IsGameAvail;
bool UpdateOnNextRun;
//Ammo Vars
bool AmmoStatus;
BYTE AmmoValue[] = {0xA3,0x1C,0x0,0x0};
DWORD AmmoBaseAddress = 0x00508B74;
DWORD AmmoOffsets[] = {0x384,0x14,0x0};
//Health Vars
bool HealthStatus;
BYTE HealthValue[] = {0x39,0x5,0x0,0x0};
DWORD HealthBaseAddress = 0x00508B74;
DWORD HealthOffsets[] = {0xF8};
int main()
{
HWND hGameWindow = NULL;
int timeSinceLastUpdate = clock();
int GameAvailTIMER = clock();
int onePressTIMER = clock();
DWORD dwProcID = NULL;
HANDLE hProcHandle = NULL;
UpdateOnNextRun = true;
std::string sAmmoStatus = "OFF";
std::string sHealthStatus = "OFF";
while(!GetAsyncKeyState(VK_INSERT))
{
if(clock() - GameAvailTIMER > 100)
{
GameAvailTIMER = clock();
IsGameAvail = false;
hGameWindow = FindWindow(NULL,LGameWindow);
if(LGameWindow)
{
GetWindowThreadProcessId(hGameWindow,&dwProcID);
if(dwProcID)
{
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS,NULL,dwProcID);
if(hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
{
GameStatus = "Failed to open process fod valid handle";
}
else
{
GameStatus = "AssaultCube Ready to hack";
IsGameAvail = true;
}
}
else
{
GameStatus = "Failed to get process ID ";
}
}
else
{
GameStatus = "AssaultCube not found";
}
if(UpdateOnNextRun || clock() - timeSinceLastUpdate > 5000)
{
system("cls");
std::cout << ".................................................." << std::endl;
std::cout << " AssaultCube memory Hacker"<<std::endl;
std::cout << ".................................................." << std::endl << std::endl;
std::cout << "Game Status:"<< GameStatus << std::endl << std::endl;
std::cout << "[F1] Unlimited Ammo -> " << sAmmoStatus << " <--" << std::endl << std::endl;
std::cout << "[F2] unlimited Health ->" << sHealthStatus << " <--" << std::endl << std::endl;
std::cout << "[INSERT] Exit " << std::endl;
UpdateOnNextRun = false;
timeSinceLastUpdate = clock();
}
if(IsGameAvail)
{
WriteTomemory(hProcHandle);
}
}
if(clock() - onePressTIMER > 400)
{
//ammo
if(GetAsyncKeyState(VK_F1))
{
onePressTIMER = clock();
AmmoStatus = !AmmoStatus;
UpdateOnNextRun = true;
if(AmmoStatus)
sAmmoStatus= "ON";
else sAmmoStatus = "OFF";
}
//health
if(GetAsyncKeyState(VK_F2))
{
onePressTIMER = clock();
HealthStatus = !HealthStatus;
UpdateOnNextRun = true;
if(HealthStatus)
sHealthStatus= "ON";
else sHealthStatus = "OFF";
}
}
}
//CloseHandle(hProcHandle);
//CloseHandle(hGameWindow);
return 0;
}
DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offset[], DWORD BaseAddres)
{
DWORD pointer = BaseAddres;
DWORD pTemp;
DWORD pointerAddr;
for(int c = 0 ; c < PointerLevel ; c++)
{
if(c == 0)
{
ReadProcessMemory(hProcHandle,(LPCVOID)pointer,&pTemp,sizeof(pTemp),NULL);
}
pointerAddr = pTemp+Offset[c];
ReadProcessMemory(hProcHandle,(LPCVOID)pointer,&pTemp,sizeof(pTemp),NULL);
}
return pointerAddr;
}
void WriteTomemory(HANDLE hProcHandle)
{
DWORD AddressToWrite;
if(AmmoStatus)
{
AddressToWrite = FindDmaAddy(3,hProcHandle,AmmoOffsets,AmmoBaseAddress);
WriteProcessMemory(hProcHandle,(BYTE*)AddressToWrite,&AmmoValue,sizeof(AmmoValue),NULL);
}
if(HealthStatus)
{
AddressToWrite = FindDmaAddy(1,hProcHandle,HealthOffsets,HealthBaseAddress);
WriteProcessMemory(hProcHandle,(BYTE*)AddressToWrite,&HealthValue,sizeof(HealthValue),NULL);
}
}