Compare angles triggerbot

Posts 16–30 of 37 · Page 2 of 3
Quote Originally Posted by WasserEsser View Post
Yes, this could result in further calculations being wrong since you are not using the value you're supposed to use.
These are the only changes I do to vectors and I normalize them after but the problem still remains.

Code:
Vector CalcAngle(Vector& src, Vector& dst, HANDLE hProc, DWORD clientDll)
{
	Vector vAngle;
	Vector delta;
	delta.x = (src.x - dst.x);
	delta.y = (src.y - dst.y);
	delta.z = (src.z - dst.z);
	Normalize(delta);
	double hyp = sqrt(delta.x*delta.x + delta.y*delta.y);

	vAngle.x = (float)(atan((delta.z + 64.06f) / hyp) * 57.295779513082f);
	vAngle.y = (float)(atan(delta.y / delta.x) * 57.295779513082f);
	vAngle.z = 0.0f;
	Normalize(vAngle);

	if (delta.x >= 0.0)
		vAngle.y += 180.0f;

	Normalize(vAngle);

	return vAngle;
}
Quote Originally Posted by samlarenskoog View Post
These are the only changes I do to vectors and I normalize them after but the problem still remains.

Code:
Vector CalcAngle(Vector& src, Vector& dst, HANDLE hProc, DWORD clientDll)
{
	Vector vAngle;
	Vector delta;
	delta.x = (src.x - dst.x);
	delta.y = (src.y - dst.y);
	delta.z = (src.z - dst.z);
	Normalize(delta);
	double hyp = sqrt(delta.x*delta.x + delta.y*delta.y);

	vAngle.x = (float)(atan((delta.z + 64.06f) / hyp) * 57.295779513082f);
	vAngle.y = (float)(atan(delta.y / delta.x) * 57.295779513082f);
	vAngle.z = 0.0f;
	Normalize(vAngle);

	if (delta.x >= 0.0)
		vAngle.y += 180.0f;

	Normalize(vAngle);

	return vAngle;
}
You should probably normalize the the angles used in the if statement aswell.
Quote Originally Posted by WasserEsser View Post
You should probably normalize the the angles used in the if statement aswell.
those are floats. Since this problem persist in my aimbot aswell the problem might be in how I get position and angles?

Code:
	Vector getPosition(HANDLE hProc, DWORD clientDll)
	{
		DWORD playerBase = getLocalPlayer(hProc, clientDll);
		if (playerBase)
		{
			return Mem.Read<Vector>(hProc, (playerBase + DwVecOrigin));
		}
	}
Code:
	Vector getViewAngle(HANDLE hProc, DWORD engineDll)
	{
		DWORD anglePointer = Mem.Read<DWORD>(hProc, (engineDll + DwEnginePointer));
		if (anglePointer)
		{
			Vector angles{};
			angles = Mem.Read<Vector>(hProc, (anglePointer + DwViewAngle));
			return angles;
		}
	}
Code:
	Vector getHeadPos(HANDLE hProc, DWORD clientDll, int playerNumber)
	{
		DWORD entityBase = getEntityBase(hProc, clientDll, playerNumber);
		if (entityBase)
		{
			DWORD boneMatrix = Mem.Read<DWORD>(hProc, (entityBase + DwBoneMatrix));
			if (boneMatrix)
			{
				Vector bonePosition{};
				bonePosition.x = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x0C));
				bonePosition.y = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x1C));
				bonePosition.z = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x2C));
				return bonePosition;
			}
		}
	}
Quote Originally Posted by samlarenskoog View Post
those are floats. Since this problem persist in my aimbot aswell the problem might be in how I get position and angles?

Code:
	Vector getPosition(HANDLE hProc, DWORD clientDll)
	{
		DWORD playerBase = getLocalPlayer(hProc, clientDll);
		if (playerBase)
		{
			return Mem.Read<Vector>(hProc, (playerBase + DwVecOrigin));
		}
	}
Code:
	Vector getViewAngle(HANDLE hProc, DWORD engineDll)
	{
		DWORD anglePointer = Mem.Read<DWORD>(hProc, (engineDll + DwEnginePointer));
		if (anglePointer)
		{
			Vector angles{};
			angles = Mem.Read<Vector>(hProc, (anglePointer + DwViewAngle));
			return angles;
		}
	}
Code:
	Vector getHeadPos(HANDLE hProc, DWORD clientDll, int playerNumber)
	{
		DWORD entityBase = getEntityBase(hProc, clientDll, playerNumber);
		if (entityBase)
		{
			DWORD boneMatrix = Mem.Read<DWORD>(hProc, (entityBase + DwBoneMatrix));
			if (boneMatrix)
			{
				Vector bonePosition{};
				bonePosition.x = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x0C));
				bonePosition.y = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x1C));
				bonePosition.z = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x2C));
				return bonePosition;
			}
		}
	}
First of all you should use m_vecOrigin + m_vecViewOffset as your source for your calcangle function.
Secondly, it has to do with angles and how angles are working in each quadrant.

I had such a problem aswell until ChrisHD told me about it.

You can normalize the float individually, all you're doing in your normalize function is normalize each float individually anyways.
Quote Originally Posted by WasserEsser View Post
First of all you should use m_vecOrigin + m_vecViewOffset as your source for your calcangle function.
Secondly, it has to do with angles and how angles are working in each quadrant.

I had such a problem aswell until ChrisHD told me about it.

You can normalize the float individually, all you're doing in your normalize function is normalize each float individually anyways.
Changing to this:
Code:
	Vector getPosition(HANDLE hProc, DWORD clientDll)
	{
		DWORD playerBase = getLocalPlayer(hProc, clientDll);
		if (playerBase)
		{
			return Mem.Read<Vector>(hProc, (playerBase + DwVecOrigin + vecViewOffset));
		}
	}
Completely fucked up the code :/ Now it fires at random positions, how come?
Quote Originally Posted by samlarenskoog View Post
Changing to this:
Code:
	Vector getPosition(HANDLE hProc, DWORD clientDll)
	{
		DWORD playerBase = getLocalPlayer(hProc, clientDll);
		if (playerBase)
		{
			return Mem.Read<Vector>(hProc, (playerBase + DwVecOrigin + vecViewOffset));
		}
	}
Completely fucked up the code :/ Now it fires at random positions, how come?
You have to read m_vecOrigin and m_vecViewOffset individually and then add the values together.
Quote Originally Posted by WasserEsser View Post
You have to read m_vecOrigin and m_vecViewOffset individually and then add the values together.
Okay, thanks for telling me . I have tried normalizing the floats individually this way:
Code:
			Vector vAnglePlus{};
			Vector vAngleMinus{};
			vAnglePlus.y = vAngle.y + 1.0f;
			vAnglePlus.x = 0.0f;
			vAnglePlus.z = 0.0f;
			vAngleMinus.y = vAngle.y - 1.0f;
			vAngleMinus.x = 0.0f;
			vAngleMinus.z = 0.0f;
			Normalize(vAnglePlus);
			Normalize(vAngleMinus);
It still does not shoot at angles from -179 to -89. Do you think ChrisHD knows how to fix this?
Quote Originally Posted by samlarenskoog View Post
Okay, thanks for telling me . I have tried normalizing the floats individually this way:
Code:
			Vector vAnglePlus{};
			Vector vAngleMinus{};
			vAnglePlus.y = vAngle.y + 1.0f;
			vAnglePlus.x = 0.0f;
			vAnglePlus.z = 0.0f;
			vAngleMinus.y = vAngle.y - 1.0f;
			vAngleMinus.x = 0.0f;
			vAngleMinus.z = 0.0f;
			Normalize(vAnglePlus);
			Normalize(vAngleMinus);
It still does not shoot at angles from -179 to -89. Do you think ChrisHD knows how to fix this?
How does your normalize function look like?
Quote Originally Posted by WasserEsser View Post
How does your normalize function look like?
Code:
void Normalize(Vector vec)
{
	if (vec.y > 180.f)
		vec.y -= 360.f;
	else if (vec.y < -180.f)
		vec.y += 360.f;

	vec.x = vec.x;
	vec.z = 0.f;
}
Quote Originally Posted by samlarenskoog View Post
Code:
void Normalize(Vector vec)
{
	if (vec.y > 180.f)
		vec.y -= 360.f;
	else if (vec.y < -180.f)
		vec.y += 360.f;

	vec.x = vec.x;
	vec.z = 0.f;
}
There is your problem. You are passing a vector as parameter instead of a reference to a vector or a pointer to a vector. This means that it will create a copy when calling the function and edit the local copy instead of the vector you passed in and use later on in the code. Change your code to receive a reference to a vector ( void Normalize( Vector& vec ) ).
Quote Originally Posted by WasserEsser View Post
There is your problem. You are passing a vector as parameter instead of a reference to a vector or a pointer to a vector. This means that it will create a copy when calling the function and edit the local copy instead of the vector you passed in and use later on in the code. Change your code to receive a reference to a vector ( void Normalize( Vector& vec ) ).
This gave me a few errors when normalizing, I guess I have to change the way i use it. Here are the errors:
Code:
error C2668: 'Normalize': ambiguous call to overloaded function
note: could be 'void Normalize(Vector &)'
note: or       'void Normalize(Vector)'
note: while trying to match the argument list '(Vector)'
- - - Updated - - -

Quote Originally Posted by WasserEsser View Post
.
Got it working but this only made it worse. Now it does not shoot at enemies, except delays and shoots somewhere random :/
Quote Originally Posted by samlarenskoog View Post
This gave me a few errors when normalizing, I guess I have to change the way i use it. Here are the errors:
Code:
error C2668: 'Normalize': ambiguous call to overloaded function
note: could be 'void Normalize(Vector &)'
note: or       'void Normalize(Vector)'
note: while trying to match the argument list '(Vector)'
:/
You have two different functions that are called Normalize.
Quote Originally Posted by WasserEsser View Post
You have two different functions that are called Normalize.
I fixed it, but as said. It only made it worse. It now it is almost a 180 degree angle where it shoots random
Quote Originally Posted by samlarenskoog View Post
I fixed it, but as said. It only made it worse. It now it is almost a 180 degree angle where it shoots random
Show your code.
Quote Originally Posted by WasserEsser View Post
Show your code.
Code:
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
#include <random>
#include <ctime>
#include <string>

using namespace std;

void click();


const DWORD DwEntityList = 0x4A4CCC4;
const DWORD DwEnginePointer = 0x5B92A4;
const DWORD DwLocalPlayer = 0xA31504;

const DWORD DwCrosshairId = 0x0000AA44;
const DWORD DwViewAngle = 0x00004D0C;
const DWORD DwVecViewOrigin = 0x104;
const DWORD DwVecOrigin = 0x134;
const DWORD DwVecPunch = 0x00003018;
const DWORD DwTeamNumber = 0xF0;
const DWORD DwShotsFired = 0xA2B0;
const DWORD DwFlags = 0x100;
const DWORD DwBoneMatrix = 0x00002698;
const DWORD DwEntitySize = 0x10;
const DWORD DwHealth = 0xFC;
const DWORD DwLifeState = 0x25B;
const DWORD DwVecVelocity = 0x110;
const DWORD vecViewOffset = 0x104;
const DWORD DwIndex = 0x00000064;
const DWORD DwSpottedByMask = 0x0000097C;
const DWORD DwSpotted = 0x00000939;
const DWORD DwAttack = 0x02E8CCD0;

int targetBone = 6;
void click();



typedef struct Vector_
{
	float x;
	float y;
	float z;
}Vector;

struct
{
	template <class type>
	type Read(HANDLE hProc, DWORD address)
	{
		type val;
		ReadProcessMemory(hProc, (LPCVOID)(address), &val, sizeof(val), NULL);
		return val;
	}

	template <class type>
	void Write(HANDLE hProc, DWORD address, type val)
	{
		WriteProcessMemory(hProc, (LPVOID)(address), &val, sizeof(val), NULL);
	}
}Mem;

DWORD getDll(DWORD pId, char* NAME)
{
	DWORD Dll = 0x0;
	MODULEENTRY32 moduleEntry;
	moduleEntry.dwSize = sizeof(MODULEENTRY32);
	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pId);
	do
	{
		if (!strcmp(moduleEntry.szModule, NAME))
		{
			Dll = (DWORD)moduleEntry.modBaseAddr;
			break;
		}
	} while (Module32Next(hSnap, &moduleEntry));
	CloseHandle(hSnap);
	return Dll;
}

struct
{
	DWORD getEntityBase(HANDLE hProc, DWORD clientDll, int playerNumber)
	{
		return Mem.Read<DWORD>(hProc, (clientDll + DwEntityList + (DwEntitySize * (playerNumber - 1))));
	}

	Vector getHeadPos(HANDLE hProc, DWORD clientDll, int playerNumber)
	{
		DWORD entityBase = getEntityBase(hProc, clientDll, playerNumber);
		if (entityBase)
		{
			DWORD boneMatrix = Mem.Read<DWORD>(hProc, (entityBase + DwBoneMatrix));
			if (boneMatrix)
			{
				Vector bonePosition{};
				bonePosition.x = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x0C));
				bonePosition.y = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x1C));
				bonePosition.z = Mem.Read<float>(hProc, (boneMatrix + 0x30 * targetBone + 0x2C));
				return bonePosition;
			}
		}
	}

	int getTeam(HANDLE hProc, DWORD clientDll, int playerNumber)
	{
		DWORD entityBase = getEntityBase(hProc, clientDll, playerNumber);
		if (entityBase)
		{
			return Mem.Read<int>(hProc, (entityBase + DwTeamNumber));
		}
	}

	int getHealth(HANDLE hProc, DWORD clientDll, int playerNumber)
	{
		DWORD entityBase = getEntityBase(hProc, clientDll, playerNumber);
		if (entityBase)
		{
			return Mem.Read<int>(hProc, (entityBase + DwHealth));
		}
	}

}Entity;

struct
{
	DWORD getLocalPlayer(HANDLE hProc, DWORD clientDll)
	{
		return Mem.Read<DWORD>(hProc, (clientDll + DwLocalPlayer));
	}

	Vector getViewAngle(HANDLE hProc, DWORD engineDll)
	{
		DWORD anglePointer = Mem.Read<DWORD>(hProc, (engineDll + DwEnginePointer));
		if (anglePointer)
		{
			Vector angles{};
			angles = Mem.Read<Vector>(hProc, (anglePointer + DwViewAngle));
			return angles;
		}
	}

	int getTeam(HANDLE hProc, DWORD clientDll)
	{
		DWORD localPlayer = getLocalPlayer(hProc, clientDll);
		if (localPlayer)
		{
			return Mem.Read<int>(hProc, (localPlayer + DwTeamNumber));
		}
	}

	Vector getPosition(HANDLE hProc, DWORD clientDll)
	{
		DWORD playerBase = getLocalPlayer(hProc, clientDll);
		if (playerBase)
		{
			return Mem.Read<Vector>(hProc, (playerBase + DwVecOrigin));
		}
	}

	Vector getEyePosition(HANDLE hProc, DWORD clientDll)
	{
		DWORD playerBase = getLocalPlayer(hProc, clientDll);
		if (playerBase)
		{
			return Mem.Read<Vector>(hProc, (playerBase + vecViewOffset));
		}
	}


}Player;

void Normalize(Vector vec)
{
	if (vec.y > 180.f)
		vec.y -= 360.f;
	else if (vec.y < -180.f)
		vec.y += 360.f;
	if (vec.x > 89.f)
		vec.x = 89.f;
	else if (vec.y < -89.f)
		vec.x = -89.f;

	vec.z = 0.f;
}

Vector CalcAngle(Vector& src, Vector& dst, HANDLE hProc, DWORD clientDll)
{
	Vector vAngle;
	Vector delta;
	delta.x = (src.x - dst.x);
	delta.y = (src.y - dst.y);
	delta.z = (src.z - dst.z);
	Normalize(delta);
	double hyp = sqrt(delta.x*delta.x + delta.y*delta.y);

	vAngle.x = (float)(atan2f(delta.z, hyp) * 57.295779513082f);
	vAngle.y = (float)(atanf(delta.y / delta.x) * 57.295779513082f);
	vAngle.z = 0.0f;
	Normalize(vAngle);

	if (delta.x >= 0.0)
		vAngle.y += 180.0f;

	Normalize(vAngle);

	return vAngle;
}

// -179 till -89 på x-axeln(pitch).
int main()
{
	DWORD pId;

	HWND hwnd = FindWindow(NULL, "Counter-Strike: Global Offensive");
	GetWindowThreadProcessId(hwnd, &pId);
	HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, NULL, pId);
	DWORD clientDll = getDll(pId, "client.dll");
	DWORD engineDll = getDll(pId, "engine.dll");

	while (true)
	{
		Vector localPosition{};
		localPosition.x = Player.getPosition(hProc, clientDll).x + Player.getEyePosition(hProc, clientDll).x;
		localPosition.y = Player.getPosition(hProc, clientDll).y + Player.getEyePosition(hProc, clientDll).y;
		localPosition.z = Player.getPosition(hProc, clientDll).z + Player.getEyePosition(hProc, clientDll).z;
		Vector viewAngle = Player.getViewAngle(hProc, engineDll);
		cout << viewAngle.y << endl;
		for (int i = 0; i < 64; ++i)
		{
			Vector headBone = Entity.getHeadPos(hProc, clientDll, i);
			Vector vAngle = CalcAngle(localPosition, headBone, hProc, clientDll);
			Vector vAnglePlus{};
			Vector vAngleMinus{};
			vAnglePlus.y = vAngle.y + 1.0f;
			vAnglePlus.x = 0.0f;
			vAnglePlus.z = 0.0f;
			vAngleMinus.y = vAngle.y - 1.0f;
			vAngleMinus.x = 0.0f;
			vAngleMinus.z = 0.0f;
			Normalize(vAnglePlus);
			Normalize(vAngleMinus);
			
			
			
			if (viewAngle.y <= vAnglePlus.y && viewAngle.y >= vAngleMinus.y && GetAsyncKeyState(0x05) && Entity.getHealth(hProc, clientDll, i) > 0 && Entity.getTeam(hProc, clientDll, i) != Player.getTeam(hProc, clientDll)) // I dont care about the elevation.
			{
				click();
			}




		}
		Sleep(1); system("cls");
	}
	return 0;
}

	void click()
	{
		mouse_event(MOUSEEVENTF_LEFTDOWN, NULL, NULL, NULL, NULL);
		Sleep(5);
		mouse_event(MOUSEEVENTF_LEFTUP, NULL, NULL, NULL, NULL);
		Sleep(10);
	}
I tried with adding a clamp in normalize function. But nothing changed.
Posts 16–30 of 37 · Page 2 of 3
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us