SolvedCalculating angle to enemy

Rake

I'm having a problem calculating angle from my local player to the enemy. I have spent 3 weeks on this and am losing my mind. I have re-written the entire aimbot 12 times, applied it to 2 different games and I get the same shitty result each time. It will aim correctly 20% of the time and other times it does not. This is one of the 12 source codes I have. I have tried with vectors, I have tried with arrays of floats, I have tried with about 15 different functions I have found on the internet and I've even tried GingerBreadMan's function that works perfectly for him. Someone save me from this hell, I've seriously spent like 30-50 hours on this. I turn on the aimbot with Numpad1 and it sets the aimangle to the target when I press Numpad2.

VectorAimbotIncludes.h
C++:
``````#include <Windows.h>
#include <iostream>
#include <string>
#include <ctime>
#include <tlhelp32.h>
#include <tchar.h>
#include <math.h>
using namespace std;
typedef DWORD OFFSET;

#define PI 					(3.1415926535897932f);
#define SMALL_NUMBER		(1.e-8f);
HANDLE hProcHandle = NULL;

LPCSTR LGameWindow = "AssaultCube";
bool bGameAvail;
bool bUpdateDisplay;

bool bAimbotStatus;
string sAimbotStatus = "OFF";

int NumOfPlayers;
UINT_PTR LocalPlayerPointer = 0x509B74;
UINT_PTR OtherPlayerArrayPointer = 0x510D90;
UINT_PTR OtherPlayerArray[31];//?

void PrintToConsole();
UINT_PTR CalculatePointer(HANDLE hProcHandle, int PointerLevel, UINT_PTR Offsets[], UINT_PTR BaseAddress);

struct Vec3_AC_POS
{
float x, z, y;
};

struct Vec3_AC_ANGLE
{
float yaw, pitch, roll;
};

float Get3dDistance(Vec3_AC_POS to, Vec3_AC_POS from);

{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcID);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry32;
ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &ModuleEntry32))
{
do
{
if (_tcsicmp(ModuleEntry32.szModule, szModuleName) == 0)
{
break;
}
} while (Module32Next(hSnapshot, &ModuleEntry32));
}
CloseHandle(hSnapshot);
}
}

DWORD CalculatePointer(HANDLE hProcHandle, int PointerLevel, DWORD Offsets[], DWORD BaseAddress)
{
DWORD TempBuffer;

for (int i = 0; i < PointerLevel; i++)
{
if (i == 0)
{
}

}
}

float Get3dDistance(Vec3_AC_POS to, Vec3_AC_POS from)
{
return (float)
(sqrt(
((to.x - from.x) * (to.x - from.x)) +
((to.y - from.y) * (to.y - from.y)) +
((to.z - from.z) * (to.z - from.z))
));
}

void PrintToConsole()
{
{
system("cls");
cout << "----------------------------------------------------" << endl;
cout << "                GuidedHacking.com                   " << endl;
cout << "        AnomanderRake's Assault Cube Aimbot         " << endl;
cout << "----------------------------------------------------" << endl << endl;
cout << "GAME STATUS: " << sGameStatus << "   " << endl << endl;
cout << "[NUMPAD1] Aimbot             -> " << sAimbotStatus << " <-" << endl << endl;
cout << "[INSERT] Exit" << endl << endl;
cout << "---------------------------------------------------" << endl;

bUpdateDisplay = false;
}
}``````
main.cpp
C++:
``````#include "VectorAimbotIncludes.h"

Vec3_AC_ANGLE CalcAngle(Vec3_AC_POS src, Vec3_AC_POS dst);

struct BestTarget_struct
{
char Name[16];
BYTE Team;
int Health;
float fLocation[3];//
float fAimbotAngles[3];//
Vec3_AC_POS vLocation;
Vec3_AC_ANGLE vAimbotAngles;
float DistanceFromMe;

}BestTarget;

struct LocalPlayer_struct
{
char Name[16];
BYTE Team;
int Health;
float fLocation[3];//
float fAimbotAngles[3];//
Vec3_AC_POS vLocation;
Vec3_AC_ANGLE vAimbotAngles;

{
}

}LocalPlayer;

struct OtherPlayers_struct
{
char Name[16];
BYTE Team;
int Health;
float fLocation[3];//
float fAimbotAngles[3];//
Vec3_AC_POS vLocation;
Vec3_AC_ANGLE vAimbotAngles;
float DistanceFromMe;

{

if (bAimbotStatus && Health > 1)
{
vAimbotAngles = CalcAngle(LocalPlayer.vLocation, OtherPlayer[i].vLocation);

//For debugging purposes I'm only calculating the angle for the first enemy.
if (i == 0)
{
BestTarget.vAimbotAngles = OtherPlayer[i].vAimbotAngles;
}

}

}

}OtherPlayer[31];

int main()
{
SetConsoleTitle("AnomanderRake's AssaultCube Aimbot");
system("mode 53, 30");

HWND hGameWindow = NULL;
DWORD dwProcId = NULL;

int timeSinceLastUpdate = clock();
int GameAvailTMR = clock();
int KeyPressTimer = clock();
bUpdateDisplay = true;

while (!GetAsyncKeyState(VK_INSERT)) //Main program loop
{

if (clock() - GameAvailTMR > 300)
{
GameAvailTMR = clock();
bGameAvail = false;
hGameWindow = FindWindow(NULL, LGameWindow);
if (hGameWindow)
{

if (dwProcId)
{

hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcId);
if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
{
sGameStatus = "Can't open process";
}
else
{
sGameStatus = "Process ID Found ac_client.exe Running";
bGameAvail = true;
}
}
else sGameStatus = "Failed to get procid";
}
else sGameStatus = "Assault Cube not running";

if (bUpdateDisplay || clock() - timeSinceLastUpdate > 3000)
{
PrintToConsole();
timeSinceLastUpdate = clock();
}

if (bGameAvail)
{
}
}

if (clock() - KeyPressTimer > 200)
{
if (bGameAvail)
{

//Turn aimbot on key
{
KeyPressTimer = clock();
bAimbotStatus = !bAimbotStatus;
bUpdateDisplay = true;
if (bAimbotStatus)
{
sAimbotStatus = "ON";

}
else
{
sAimbotStatus = "OFF";
}
}

//AimWhenPressedHotkey
{
KeyPressTimer = clock();
//bAimStatus = !bAimStatus;
bUpdateDisplay = true;
if (bAimbotStatus)
{

WriteProcessMemory(hProcHandle, (PBYTE*)(LocalPlayer.PlayerAddress + 0x40), &BestTarget.vAimbotAngles, 8, 0);
}
}

}
}
}//end of main program loop

CloseHandle(hProcHandle);
CloseHandle(hGameWindow);

return ERROR_SUCCESS;
}

{

for (int i = 0; i < NumOfPlayers; i++)
{
}
}

Vec3_AC_ANGLE CalcAngle(Vec3_AC_POS src, Vec3_AC_POS dst)
{
Vec3_AC_ANGLE angles;
double delta[3] = { (src.x - dst.x), (src.y - dst.y), (src.z - dst.z) };
double hyp = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
angles.pitch = (float)(asinf(delta[2] / hyp) * 57.295779513082f);
angles.yaw = (float)(atanf(delta[1] / delta[0]) * 57.295779513082f);
angles.roll = 0.0f;

if (delta[0] >= 0.0)
{
angles.yaw += 180.0f;
}

return angles;
}``````

Rake

The game designer can choose what X Y and Z mean in his code. I thought these equaled the same thing in every game and that it was only the order they were listed in that could change. But reality from what we learned from this example is that X Y and Z can be any direction that the developer chooses. The developer chooses a cartesian coordinate system by defining the directions.

So here is an updated picture for Assault Cube:

Updated Coordinates Offset
+034 = LocationX - Move left and right
+038 = LocationY - Move forward and backwards
+03C = LocationZ - Move vertically up and down

And the definition straight from AC source code:

C++:
``short x, y, z;  //position``

https://gamedev.stackexchange.com/questions/46225/why-is-y-up-in-many-games
https://gamedev.stackexchange.com/questions/13414/x-y-z-coordinate-standards

Thank you x100 GBM

Last edited:

Solaire

Respected Hacker
Dank Tier VIP
C++:
``````struct Vec3_AC_POS
{
float x, z, y;
};``````
AssaultCube has the Coords stored as X Y Z. You have it as X Z Y. That is part of the problem there . I'm not sure if the calcangle you're using is part of the problem or not. When I tried to use one that didn't have math for each separate sector, it caused issues.

EDIT:
Yep, that pretty much solved it. The only other thing I had to do was add 90 to the yaw and it works. One thing that I recommend; remove the "update screen" thing. It doesn't work with the aimbot because it updates constantly while the aimbot is turned on, causing it to be uselessly slow.

Here's the fixed code with comments where I changed something:
VectorAimbotIncludes.h
C++:
``````#include <Windows.h>
#include <iostream>
#include <string>
#include <ctime>
#include <tlhelp32.h>
#include <tchar.h>
#include <math.h>
using namespace std;
typedef DWORD OFFSET;

#define PI                  (3.1415926535897932f);
#define SMALL_NUMBER        (1.e-8f);
HANDLE hProcHandle = NULL;

LPCSTR LGameWindow = "AssaultCube";
bool bGameAvail;
bool bUpdateDisplay;

bool bAimbotStatus;
string sAimbotStatus = "OFF";

int NumOfPlayers;
UINT_PTR LocalPlayerPointer = 0x509B74;
UINT_PTR OtherPlayerArrayPointer = 0x510D90;
UINT_PTR OtherPlayerArray[31];//?

void PrintToConsole();
UINT_PTR CalculatePointer(HANDLE hProcHandle, int PointerLevel, UINT_PTR Offsets[], UINT_PTR BaseAddress);

struct Vec3_AC_POS
{
float x, y, z;//XYZ, not XZY
};

struct Vec3_AC_ANGLE
{
float yaw, pitch, roll;
};

float Get3dDistance(Vec3_AC_POS to, Vec3_AC_POS from);

{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcID);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry32;
ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &ModuleEntry32))
{
do
{
if (_tcsicmp(ModuleEntry32.szModule, szModuleName) == 0)
{
break;
}
} while (Module32Next(hSnapshot, &ModuleEntry32));
}
CloseHandle(hSnapshot);
}
}

DWORD CalculatePointer(HANDLE hProcHandle, int PointerLevel, DWORD Offsets[], DWORD BaseAddress)
{
DWORD TempBuffer;

for (int i = 0; i < PointerLevel; i++)
{
if (i == 0)
{
}

}
}

float Get3dDistance(Vec3_AC_POS to, Vec3_AC_POS from)
{
return (float)
(sqrt(
((to.x - from.x) * (to.x - from.x)) +
((to.y - from.y) * (to.y - from.y)) +
((to.z - from.z) * (to.z - from.z))
));
}

void PrintToConsole()
{
{
system("cls");
cout << "----------------------------------------------------" << endl;
cout << "                GuidedHacking.com                   " << endl;
cout << "        AnomanderRake's Assault Cube Aimbot         " << endl;
cout << "----------------------------------------------------" << endl << endl;
cout << "GAME STATUS: " << sGameStatus << "   " << endl << endl;
cout << "[NUMPAD1] Aimbot             -> " << sAimbotStatus << " <-" << endl << endl;
cout << "[INSERT] Exit" << endl << endl;
cout << "---------------------------------------------------" << endl;

bUpdateDisplay = false;
}
}``````
main.cpp
C++:
``````#include "VectorAimbotIncludes.h"

Vec3_AC_ANGLE CalcAngle(Vec3_AC_POS src, Vec3_AC_POS dst);

struct BestTarget_struct
{
char Name[16];
BYTE Team;
int Health;
float fLocation[3];//
float fAimbotAngles[3];//
Vec3_AC_POS vLocation;
Vec3_AC_ANGLE vAimbotAngles;
float DistanceFromMe;

}BestTarget;

struct LocalPlayer_struct
{
char Name[16];
BYTE Team;
int Health;
float fLocation[3];//
float fAimbotAngles[3];//
Vec3_AC_POS vLocation;
Vec3_AC_ANGLE vAimbotAngles;

{
}

}LocalPlayer;

struct OtherPlayers_struct
{
char Name[16];
BYTE Team;
int Health;
float fLocation[3];//
float fAimbotAngles[3];//
Vec3_AC_POS vLocation;
Vec3_AC_ANGLE vAimbotAngles;
float DistanceFromMe;

{

if (bAimbotStatus && Health > 1)
{
vAimbotAngles = CalcAngle(LocalPlayer.vLocation, OtherPlayer[i].vLocation);

//For debugging purposes I'm only calculating the angle for the first enemy.
if (i == 0)
{
BestTarget.vAimbotAngles = OtherPlayer[i].vAimbotAngles;
}

}

}

}OtherPlayer[31];

int main()
{
SetConsoleTitle("AnomanderRake's AssaultCube Aimbot");
system("mode 53, 30");

HWND hGameWindow = NULL;
DWORD dwProcId = NULL;

int timeSinceLastUpdate = clock();
int GameAvailTMR = clock();
int KeyPressTimer = clock();
bUpdateDisplay = true;

while (!GetAsyncKeyState(VK_INSERT)) //Main program loop
{

if (clock() - GameAvailTMR > 300)
{
GameAvailTMR = clock();
bGameAvail = false;
hGameWindow = FindWindow(NULL, LGameWindow);
if (hGameWindow)
{

if (dwProcId)
{

hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcId);
if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
{
sGameStatus = "Can't open process";
}
else
{
sGameStatus = "Process ID Found ac_client.exe Running";
bGameAvail = true;
}
}
else sGameStatus = "Failed to get procid";
}
else sGameStatus = "Assault Cube not running";

if (bUpdateDisplay || clock() - timeSinceLastUpdate > 3000)
{
PrintToConsole();
timeSinceLastUpdate = clock();
}

if (bGameAvail)
{
}
}

if (clock() - KeyPressTimer > 200)
{
if (bGameAvail)
{

//Turn aimbot on key
{
KeyPressTimer = clock();
bAimbotStatus = !bAimbotStatus;
bUpdateDisplay = true;
if (bAimbotStatus)
{
sAimbotStatus = "ON";

}
else
{
sAimbotStatus = "OFF";
}
}

//AimWhenPressedHotkey
{
KeyPressTimer = clock();
//bAimStatus = !bAimStatus;
bUpdateDisplay = true;
if (bAimbotStatus)
{

WriteProcessMemory(hProcHandle, (PBYTE*)(LocalPlayer.PlayerAddress + 0x40), &BestTarget.vAimbotAngles, 8, 0);
}
}

}
}
}//end of main program loop

CloseHandle(hProcHandle);
CloseHandle(hGameWindow);

return ERROR_SUCCESS;
}

{

for (int i = 0; i < NumOfPlayers; i++)
{
}
}

Vec3_AC_ANGLE CalcAngle(Vec3_AC_POS src, Vec3_AC_POS dst)
{
Vec3_AC_ANGLE angles;
double delta[3] = { (src.x - dst.x), (src.y - dst.y), (src.z - dst.z) };
double hyp = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
angles.pitch = (float)(asinf(delta[2] / hyp) * 57.295779513082f);
angles.yaw = (float)(atanf(delta[1] / delta[0]) * 57.295779513082f);
angles.roll = 0.0f;

if (delta[0] >= 0.0)
{
angles.yaw += 180.0f;
}

angles.yaw += 90;//this moves the camera on to the player, otherwise you go in a circle around them
//(kinda fun to do that though, if you ask me :P)

return angles;
}``````

Rake

Thanks you GBM I will be trying that out right away, and I noticed the UpdateScreen thing also

In AC I have Location listed as offsets:
+034 = LocationX - Move left and right
+038 = LocationZ - Move forward and backwards
+03C = LocationY - Move vertically up and down

Because of this:

But you're telling my AC stores location as X, Y then Z.
So who is wrong the picture or you? Or am I fucking retarded

Last edited:

Solaire

Respected Hacker
Dank Tier VIP
I believe I read somewhere that in D3D games it's stored as XZY (that would be most). In other types, such as OpenGL, it's XYZ. Where in both situations Z is the Up/Down coordinates. This is mostly a guess, but it's worked so far for me. The best way to check what type your game is, is to go into memory and look at the three floats in the data/structure dissector in Cheat Engine. Jump up and down and if the one in the middle changes it's XZY. Otherwise, it's most likely XYZ.

Attention! Before you post:

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