Solved C++ DLL AimBot Error ("run-time check failure #3"):/

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

MeLThRoX

Newbie
Apr 4, 2016
4
122
0
As my first project I am trying to make an AimBot in Assault Cube. I am almost done but at the end there is an error. Sometimes not always there is a messagebox which says "run-time check failure #3".What does that mean?

P.S. I know the code is a little bit strong to understand:/ Thats because I am a newbie:p

C++:
#include <Windows.h>

DWORD getAddress(DWORD baseAddr, DWORD offset1)
{
	DWORD addr = ((*(DWORD*)(baseAddr)) + offset1);
	return addr;
}

DWORD getAddress(DWORD baseAddr, DWORD offset1, DWORD offset2)
{
	DWORD addr = ((*(DWORD*)((*(DWORD*)(baseAddr)) + offset1)) + offset2);
	return addr;
}

DWORD getAddress(DWORD baseAddr, DWORD offset1, DWORD offset2, DWORD offset3)
{
	DWORD addr = ((*(DWORD*)((*(DWORD*)((*(DWORD*)(baseAddr)) + offset1)) + offset2)) + offset3);
	return addr;
}

DWORD getAddress(DWORD baseAddr, DWORD offset1, DWORD offset2, DWORD offset3, DWORD offset4)
{
	DWORD addr = ((*(DWORD*)((*(DWORD*)((*(DWORD*)((*(DWORD*)(baseAddr)) + offset1)) + offset2)) + offset3)) + offset4);
	return addr;
}

DWORD getAddress(DWORD baseAddr, DWORD offset1, DWORD offset2, DWORD offset3, DWORD offset4, DWORD offset5)
{
	DWORD addr = ((*(DWORD*)((*(DWORD*)((*(DWORD*)((*(DWORD*)((*(DWORD*)(baseAddr)) + offset1)) + offset2)) + offset3)) + offset4)) + offset5);
	return addr;
}

C++:
#include "func.h"
#include <Windows.h>
#include <tlhelp32.h>
#include <Psapi.h>
#include <cstring>
#include <string>
#include <math.h>

#define BASE_ADDR 0x00400000
#define PI 3.14159265

using namespace std;

void MsgBox(LPCSTR text)
{
	MessageBoxA(NULL, text, "ac_hack", MB_OK);
}

void MsgBoxFloat(float nmbr)
{
	char buffer[1024];
	sprintf_s(buffer, "%f\n", nmbr);
	MessageBoxA(NULL, buffer, "Float", MB_OK);
}

void MsgBoxInteger(int nmbr)
{
	char buffer[1024];
	sprintf_s(buffer, "%d", nmbr);
	MessageBoxA(NULL, buffer, "Integer", MB_OK);
}


void MsgBoxAddr(DWORD addr)
{
	char buffer[1024];
	sprintf_s(buffer, "Address: 0x%02x", addr);
	MessageBoxA(NULL, buffer, "ac_hack", MB_OK);
}

DWORD getClosestEnemyAddress(DWORD EnemyBase, int PlayerCount, float xPlayerPos, float yPlayerPos, float zPlayerPos)
{
	DWORD CurrentOffset = 0x00;
	float distance = 0;
	DWORD Address;
	DWORD CurrentAddress;
	bool first = true;

	for (int i = 0; i < PlayerCount ; ++i)
	{
		CurrentAddress = getAddress(BASE_ADDR + 0x00110D90, CurrentOffset, 0xf8);
		int *health = (int*)(CurrentAddress);
		float *xEnemyPos = (float*)(CurrentAddress - 0xC4 + 0x00);
		float *yEnemyPos = (float*)(CurrentAddress - 0xC4 + 0x04);
		float *zEnemyPos = (float*)(CurrentAddress - 0xC4 + 0x08);
		float calculation = sqrt(pow(*xEnemyPos - xPlayerPos, 2) + pow(*yEnemyPos - yPlayerPos, 2) + pow(*zEnemyPos - zPlayerPos, 2));
		if (calculation < distance || first == true)
		{
			if (*health > 0)
			{
				distance = calculation;
				Address = CurrentAddress;
			}
		}
		CurrentOffset += 0x04;
		first = false;
	}

	return Address;
}

void AimBot() 
{
	Sleep(100);
	DWORD EnemyBase = (BASE_ADDR + 0x00110D90);
	int *PlayerCount = (int*)(EnemyBase + 0x08);
	if (*PlayerCount > 0)
	{
		//Variables
		float xCalcMous;
		float yCalcMous;
		DWORD PlayerHealthAddr = getAddress(BASE_ADDR + 0x00109B74, 0xf8);
		float *xPlayerPos = (float*)(PlayerHealthAddr - 0xC4 + 0x00);
		float *yPlayerPos = (float*)(PlayerHealthAddr - 0xC4 + 0x04);
		float *zPlayerPos = (float*)(PlayerHealthAddr - 0xC4 + 0x08);
		DWORD xMousAddr = (PlayerHealthAddr - 0xC4 + 0x10);
		DWORD yMousAddr = (PlayerHealthAddr - 0xC4 + 0x0C);
		DWORD EnemyHealthAddr = getClosestEnemyAddress(EnemyBase, *PlayerCount, *xPlayerPos, *yPlayerPos, *zPlayerPos);

		int *EnemyHealth = (int*)(EnemyHealthAddr);
		float *xEnemyPos = (float*)(EnemyHealthAddr - 0xC4 + 0x00);
		float *yEnemyPos = (float*)(EnemyHealthAddr - 0xC4 + 0x04);
		float *zEnemyPos = (float*)(EnemyHealthAddr - 0xC4 + 0x08);

		//Calculations
		if (*xPlayerPos < *xEnemyPos)
		{
			xCalcMous = (float)(90 - (atan((*yEnemyPos - *yPlayerPos) / (*xPlayerPos - *xEnemyPos)) * 180 / PI));
		}
		else if (*xPlayerPos > *xEnemyPos)
		{
			xCalcMous = (float)(360 - 90 - (atan((*yEnemyPos - *yPlayerPos) / (*xPlayerPos - *xEnemyPos)) * 180 / PI));
		}
		yCalcMous = (float)(atan((*zEnemyPos - *zPlayerPos) / sqrt(pow(*xEnemyPos - *xPlayerPos, 2) + pow(*yPlayerPos - *yEnemyPos, 2))) * 180 / PI);

		//Set Mous
		if (*EnemyHealth > 0)
		{
			*(float*)yMousAddr = xCalcMous;
			*(float*)xMousAddr = yCalcMous;
		}
	}
}

void main()
{
	while (true)
	{
		if (GetAsyncKeyState(VK_CONTROL))
		{
			AimBot();
		}
		if (GetAsyncKeyState(VK_F1))
		{
			MsgBox("It Works!");
		}
	}
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD  dwReason, LPVOID lpReserved)
{
	if (dwReason == DLL_PROCESS_ATTACH)
	{
		MsgBox("DLL Attached");
		CreateThread(0, 0, (LPTHREAD_START_ROUTINE)main, 0, 0, 0);
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		MsgBox("DLL detached");
		ExitProcess(1);
	}
	return TRUE;
}
 

Lukor

ded
Meme Tier VIP
Fleep Tier Donator
Dec 13, 2013
496
5,753
25
uninitialized variable

check your getClosestEnemyAddress() func.
You do not set a value for Address in case no players health is above 0.
DWORD Address = 0x0;
 
Last edited by a moderator:

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,204
78,998
2,400
Does it compile? What version of visual studio are you using?
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,204
78,998
2,400
Yes, it does. Visual Studio 2013 Express Edition.
I'm not sure what the problem is, watch this video and learn how to debug and find your problem:

If you attach the debugger and it has an error it will give you more information regarding your crash
 
Last edited:

Amonomen

Resident A$$hole
Dank Tier Donator
May 1, 2016
22
373
1
Your CreateThread call is different from the ones I typically use. (doesn't mean I'm doing it correctly...)
Your call:
C++:
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)main, 0, 0, 0);
My call would be:
C++:
CreateThread(0, 0x1000, (LPTHREAD_START_ROUTINE)main, 0, 0, 0);
The second param of CreateThread is the stack size.
Again, just because I do it differently, doesn't mean it's right.


Also, to narrow down the failing method, you can write to a log file.

Include stdio.h:
C++:
#include <stdio.h>
Add a FILE pointer in the global scope:
C++:
FILE *logFile;
Modify your main:
C++:
void main()
{
    logFile = fopen("C:\\Your_Path_here", "w+") // use "w+" to overwrite each time the dll is loaded.
    while (true)
    {
        if (GetAsyncKeyState(VK_CONTROL))
        {
            AimBot();
        }
        if (GetAsyncKeyState(VK_F1))
        {
            MsgBox("It Works!");
        }
    }
    fflush(logFile);
    fclose(logFile); // We don't NEED this for what we are doing here because the parent program will clean up for us, but it is good practice to clean up after yourself.
}
Then write to the file each time a method is called:
C++:
void MyMethod()
{
     fprintf(logFile, "Entering MyMethod()");
     fflush(logFile) // call fflush() to clear the buffer and write to the file incase this is the faulty method. If the program crashes while there is data in the buffer, it will not be written to the file.
    ...
    fprintf(logFile, "Leaving MyMethod()");
}
This is just something I use because after I narrow down the problem to a single method, it's usually pretty easy from there to spot the issue.
Using a debugger will give you better results, but isn't as simple to use.
 
Last edited:

Alex

Sober linux neb
Dank Tier Donator
Nobleman
Nov 26, 2015
150
828
1
MeLThRoX If you are using a uninitialized variable before giving it a value somewhere in your code, it sometimes gives you that run-time error, but i dont know if that's the case here cus i haven't read your code(too lazy for it).
 
Last edited:
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