#include <iostream>
#include <windows.h>
#include <string>
#include <ctime>
using namespace std;
DWORD findAddr(int &pointerlevel, DWORD &baseAddress, DWORD baseOffsets[]);
void writeToAddr(void);
namespace ammo
{
bool ammoStatus = false;
DWORD ammoBaseAddress = 0x004DF73C;
DWORD ammoBaseOffsets[] = {0x378, 0x14, 0x00};
int ammoPointerlevel = 3;
BYTE ammoValue[] = {0xA3, 0x1C, 0x00, 0x00};
}
namespace health
{
bool healthStatus = false;
DWORD healthBaseAddress = 0x004DF73C;
DWORD healthBaseOffsets[] = {0xF4};
int healthPointerlevel = 1;
BYTE healthValue[] = {0x39, 0x05, 0x00, 0x00};
}
namespace myHandles
{
HWND hGameWindow = 0;
DWORD dwProcID = 0;
HANDLE hProcHandle = 0;
}
using namespace ammo;
using namespace health;
using namespace myHandles;
int main(void)
{
int lastUpdateTMR = clock();
int gameAvailCheckTMR = clock();
int onePressTMR = clock();
bool isGameAvail;
bool updateOnNextRun = true;
string sGameStatus;
string sAmmoStatus = "OFF";
string sHealthStatus = "OFF";
while(!GetAsyncKeyState(VK_INSERT))
{
if((clock() - gameAvailCheckTMR) > 100) //Game available check and console update
{
gameAvailCheckTMR = clock();
isGameAvail = false;
hGameWindow = FindWindow(NULL, (LPCSTR)"AssaultCube");
if(hGameWindow)
{
GetWindowThreadProcessId(hGameWindow, &dwProcID);
if(dwProcID)
{
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, false, dwProcID);
if(!hProcHandle)
{
sGameStatus = "Failed to open process for valid handle";
}
else
{
sGameStatus = "AssaultCube is now ready to hack";
isGameAvail = true;
}
}
else
{
sGameStatus = "Failed to get processID";
}
}
else
{
sGameStatus = "Searching for AssaultCube...";
}
if(updateOnNextRun || (clock() - lastUpdateTMR) > 5000)
{
system("cls");
cout << "********************************************" << endl;
cout << " External AssaultCube Memory Hacker " << endl;
cout << "********************************************" << endl << endl;
cout << "GAME STATUS: " << sGameStatus << endl << endl;
cout << "[F1] Unlimited ammo ->" << sAmmoStatus << "<-" << endl;
cout << "[F2] Unlimited health ->" << sHealthStatus << "<-" << endl;
cout << "[INSERT] Exit" << endl;
updateOnNextRun = false;
lastUpdateTMR = clock();
}
if(isGameAvail)
{
writeToAddr();
}
}
if((clock() - onePressTMR) > 400) // interaction
{
if(isGameAvail)
{
if(GetAsyncKeyState(VK_F1))
{
onePressTMR = clock();
ammoStatus = !ammoStatus;
updateOnNextRun = true;
if(ammoStatus)
{
sAmmoStatus = "ON";
}
else
{
sAmmoStatus = "OFF";
}
}
if(GetAsyncKeyState(VK_F2))
{
onePressTMR = clock();
healthStatus = !healthStatus;
updateOnNextRun = true;
if(healthStatus)
{
sHealthStatus = "ON";
}
else
{
sHealthStatus = "OFF";
}
}
}
}
}
CloseHandle(hProcHandle);
CloseHandle(hGameWindow);
return 0;
}
DWORD findAddr(int &pointerlevel, DWORD &baseAddress, DWORD baseOffsets[])
{
DWORD pTemp;
DWORD pointer;
ReadProcessMemory(hProcHandle, (LPCVOID)baseAddress, &pTemp, sizeof(pTemp), NULL);
for(int c=0; c<pointerlevel; c++)
{
pointer = pTemp + baseOffsets[c];
ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
}
return pointer;
}
void writeToAddr(void)
{
DWORD addressToWrite;
if(ammoStatus)
{
addressToWrite = findAddr(ammoPointerlevel, ammoBaseAddress, ammoBaseOffsets);
WriteProcessMemory( hProcHandle, (BYTE*)addressToWrite, &ammoValue, sizeof(ammoValue), NULL);
}
if(healthStatus)
{
addressToWrite = findAddr(healthPointerlevel, healthBaseAddress, healthBaseOffsets);
WriteProcessMemory( hProcHandle, (BYTE*)addressToWrite, &healthValue, sizeof(healthValue), NULL);
}
}