Solved Game Crashes when I click a keybind for Ammo Hack or Health Hack

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

neonplanet

Newbie
Meme Tier VIP
Dank Tier Donator
Sep 7, 2017
248
4,078
13
So I'm following the video series for a Console Trainer. And I've been stuck on this for 2 days. Everytime I click the keybind to activate the hack the game crashes with an error code: "Win32 Expiation: 0xc0000005 [0x0] ()" Thats the error code for Ammo Hack.

Error code for the health hack being activated is: "Win32 Exception: 0xc0000005 [0x541] ()"

The offsets are 100% right, I checked the offsets twice and came up with the same offsets both times.



C++:
 #include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>

DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress);
void WriteToMemory(HANDLE hProcHandle);


std::string GameName = "AssaultCube";
LPCSTR LGameWindow = "AssaultCube";
std::string GameStatus;

bool IsGameAvail;
bool UpdateOnNextRun;

//AMMO VARS
bool AmmoStatus = false; 
BYTE AmmoValue[] = { 0x64 };
DWORD AmmoBaseAddress = { 0x00509B74 };
DWORD AmmoOffsets[] = { 0x0, 0x14, 0x384};

//AMMO VARS
bool HealthStatus = false;
BYTE HealthValue[] = { 0x39, 0x5, 0x0, 0x0 };
DWORD HealthBaseAddress = { 0x00509B74 };
DWORD HealthOffsets[] = { 0xF8 };


int main() {
	HWND hGameWindow = NULL;
	int timeSinceLastUpdate = clock();
	int GameAvailTMR = clock();
	int onePressTMR = clock();

	DWORD dwProcID = NULL;
	HANDLE hProcHandle = NULL;
	UpdateOnNextRun = true;
	std::string sAmmoStatus = "OFF";
	std::string sHealthStatus = "OFF";

	while (!GetAsyncKeyState(VK_INSERT))
	{
		if (clock() - GameAvailTMR > 100)
		{
			GameAvailTMR = clock();
			IsGameAvail = false;

			hGameWindow = FindWindow(NULL, LGameWindow);
			if (hGameWindow)
			{
				GetWindowThreadProcessId(hGameWindow, &dwProcID);
				if (dwProcID != 0)
				{
					hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
					if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
					{
						GameStatus = "Failed to open process for 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] Unlmited Ammo ->" << sAmmoStatus << " <- " << std::endl << std::endl;
				std::cout << "[F2] Unlmited Health ->" << sHealthStatus << " <- " << std::endl << std::endl;
				std::cout << "[INSERT] Exit" << std::endl;
				UpdateOnNextRun = false;
				timeSinceLastUpdate = clock();
			}

			if (IsGameAvail)
			{
				WriteToMemory(hProcHandle);
			}
		}
		if (clock() - onePressTMR > 400)
		{
			if (IsGameAvail)
			{
				//ammo
				if (GetAsyncKeyState(VK_F1))
				{
					onePressTMR = clock();
					AmmoStatus = !AmmoStatus;
					UpdateOnNextRun = true;
					if (AmmoStatus)sAmmoStatus = "ON";
					else sAmmoStatus = "OFF";
				}
				//health
				else if (GetAsyncKeyState(VK_F2))
				{
					onePressTMR = clock();
					HealthStatus = !HealthStatus;
					UpdateOnNextRun = true;
					if (HealthStatus)sHealthStatus = "ON";
					else sHealthStatus = "OFF";
				}
			}
		}
	}
	CloseHandle(hProcHandle);
	CloseHandle(hGameWindow);

	return ERROR_SUCCESS;


}

DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
{
	DWORD pointer = BaseAddress;
	DWORD  pTemp;

	DWORD pointerAddr;
	for (int c = 0; c < PointerLevel; c++)
	{
		if (c == 0)
		{
			ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
		}
		pointerAddr = pTemp + Offsets[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(3, hProcHandle, HealthOffsets, HealthBaseAddress);
		WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &HealthValue, sizeof(HealthValue), NULL);
	}
}
 
Last edited by a moderator:

Traxin

Escobar Tier VIP
Dank Tier Donator
Aug 3, 2015
1,041
25,378
154
What line exactly is throwing the exception?
I understand the pointer paths may be correct, but double check the result of the FindDmaAddy function to make sure you're returning the correct address.
Other then that it looks fine.
Oh.. And use [ cpp ] tags for highlighting.

Edit:
Welp, found it. Hopefully people don't ruin it by posting what it is you did wrong because I'd like you to find it for yourself though.
Like I said before, make sure to step through your code in the debugger, my previous advice still stands; follow it and you will find the error in your code.
Minor detail but hopefully you'll learn something ;)
 
Last edited:

neonplanet

Newbie
Meme Tier VIP
Dank Tier Donator
Sep 7, 2017
248
4,078
13
What line exactly is throwing the exception?
I understand the pointer paths may be correct, but double check the result of the FindDmaAddy function to make sure you're returning the correct address.
Other then that it looks fine.
Oh.. And use [ cpp ] tags for highlighting.

Edit:
Welp, found it. Hopefully people don't ruin it by posting what it is you did wrong because I'd like you to find it for yourself though.
Like I said before, make sure to step through your code in the debugger, my previous advice still stands; follow it and you will find the error in your code.
Minor detail but hopefully you'll learn something ;)
Okay thank you so much. One more question should I use breakpoints to debug the program?
 

wolf22j

Coder
Full Member
Nobleman
Mar 19, 2014
133
1,778
20
Okay thank you so much. One more question should I use breakpoints to debug the program?
Yes, set a bp on the area where you think/know the issue is happening, then step through the code from there.
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods