Results 1 to 11 of 11
  1. #1
    samlarenskoog's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    104
    Reputation
    25
    Thanks
    57
    My Mood
    Cheerful

    Get Closest Enemy To Crosshair Failing

    Hello guys!
    Recently I implemented a getClosestEntityToCrosshair function but it does not seem to work, I only have 0 returned. I have checked it and I cant see the problem. All it does is spins around aiming no where particular and sometimes I enter invalid angles for some reason. :/


    Code:
    Vector MakeVector(Vector pfin)
    {
    	float pitch = (float)(pfin.x * 57.295779513082f);
    	float yaw = (float)(pfin.y * 57.295779513082f);
    	float tmp = (float)(cos(pitch));
    
    	Vector vector{};
    	vector.x = (float)(-tmp * -cos(yaw));
    	vector.y = (float)(sin(yaw)*tmp);
    	vector.z = (float)(-sin(pitch));
    	Normalize(vector);
    	return vector;
    }
    
    float GetFOV(Vector Angles, Vector Source, Vector Dst, HANDLE hProc, DWORD clientDll)
    {
    	Vector ang{}, aim{};
    	float fov;
    	ang = CalcAngle(Source, Dst, hProc, clientDll);
    	Normalize(ang);
    	aim = MakeVector(Angles);
    	ang = MakeVector(ang);
    
    	float mag_s = sqrt((aim.x * aim.x) + (aim.y * aim.y) + (aim.z * aim.z));
    	float mag_d = sqrt((aim.x * aim.x) + (aim.y * aim.y) + (aim.z * aim.z));
    
    	float u_dot_v = aim.x * ang.x + aim.y * ang.y + aim.z * ang.z;
    	fov = acos(u_dot_v / (mag_s*mag_d)) * (57.295779513082f);
    
    	return fov;
    }
    
    int getClosestToCrosshair(HANDLE hProc, DWORD clientDll, DWORD engineDll)
    {
    
    	float maxFov = 30.0f;
    	Vector bonePosition{};
    	int closestEnt = NULL;
    
    	for (int i = 0; i < 32; i++)
    	{
    	DWORD ent = Entity.getEntityBase(hProc, clientDll, i);
    	if (!ent)
    		continue;
    
    	if (ent == Player.getLocalPlayer(hProc, clientDll))
    		continue;
    	
    
    	Vector localPosition = Player.getPosition(hProc, clientDll);
    	Vector localViewAngles = Player.getViewAngle(hProc, engineDll);
    
    	bool isDormant = Mem.Read<bool>(hProc, (ent + DwDormant));
    	int entHealth = Mem.Read<int>(hProc, (ent + DwHealth));
    	DWORD boneMatrix = Mem.Read<DWORD>(hProc, (ent + DwBoneMatrix));
    	if (boneMatrix)
    	{
    		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));
    	}
    	if (isDormant)
    		continue;
    	
    	int entitylifestate = Mem.Read<byte>(hProc, ent + 0x0000025B);
    	if (entitylifestate != 0)
    		continue;
    	
    
    	if (entHealth > 0 && Entity.getTeam(hProc, clientDll, closestEnt) != Player.getTeam(hProc, clientDll))
    	{
    		float fov = GetFOV(localViewAngles, localPosition, bonePosition, hProc, clientDll);
    		if (fov < maxFov)
    		{
    			maxFov = fov;
    			closestEnt = i;
    
    		}
    	}
    	}
    	return closestEnt;
    }
    Implementation:
    Code:
    if (GetAsyncKeyState(0x01) < 0 || GetAsyncKeyState(0x05) < 0)
    		{
    			
    			
    
    			Vector localPosition = Player.getPosition(hProc, clientDll);
    			Vector viewAngle = Player.getViewAngle(hProc, engineDll);
    			cout << viewAngle.x << endl << viewAngle.y << endl;
    			
    				int closestEnt = getClosestToCrosshair(hProc, clientDll, engineDll);
    				Vector headBone = Entity.getHeadPos(hProc, clientDll, closestEnt);
    				Vector vAngle = CalcAngle(localPosition, headBone, hProc, clientDll);
    				Normalize(vAngle);
    				
    				cout << vAngle.x << endl << vAngle.y << endl << endl << closestEnt;
    
    
    				
    					Vector newAngles = smoothAngleFunc(vAngle, viewAngle, engineDll, hProc);
    					Normalize(newAngles);
    					Player.setViewAngle(hProc, engineDll, newAngles);
    				
    			
    
    			Sleep(1);
    Currently I am using a similar method to get the closest player to crosshair but it is defect. There is a dark 90 degree angle on every map where this does not lock on targets.

    Code:
    	float shortestDif = 5.f;
    			Vector closestAng{};
    
    			Vector localPosition = Player.getPosition(hProc, clientDll);
    			Vector viewAngle = Player.getViewAngle(hProc, engineDll);
    			cout << viewAngle.x << endl << viewAngle.y << endl;
    			for (int i = 0; i < 32; ++i)
    			{
    				Vector headBone = Entity.getHeadPos(hProc, clientDll, i);
    				Vector vAngle = CalcAngle(localPosition, headBone, hProc, clientDll);
    				Normalize(vAngle);
    				
    			
    
    				if (Entity.getHealth(hProc, clientDll, i) > 0 && Entity.getTeam(hProc, clientDll, i) != Player.getTeam(hProc, clientDll) && i > 0)
    				{
    					float angDif = abs(viewAngle.x - vAngle.x) + abs(viewAngle.y - vAngle.y);
    
    					if (angDif < shortestDif)
    					{
    						shortestDif = angDif;
    						closestAng.x = vAngle.x;
    						closestAng.y = vAngle.y;
    						closestAng.z = vAngle.z;
    						Normalize(closestAng);						
    					}
    				}
    			}
    
    			if (shortestDif != 5.f)
    			{
    				//do aimbot stuff
    			}

    I would be really gratefull if anyone could look through the code in search for errors.
    Last edited by samlarenskoog; 07-17-2016 at 06:07 PM.

  2. #2
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Show us your smoothAngleFunc function.
    You should also use the position of your viewangles as source ( m_vecOrigin + m_vecViewOffset ).

  3. #3
    samlarenskoog's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    104
    Reputation
    25
    Thanks
    57
    My Mood
    Cheerful
    Quote Originally Posted by WasserEsser View Post
    Show us your smoothAngleFunc function.
    You should also use the position of your viewangles as source ( m_vecOrigin + m_vecViewOffset ).
    Code:
    Vector smoothAngleFunc(Vector dest, Vector orig, DWORD engineDll, HANDLE hProc)
    {
    	Vector smoothAngles{};
    	smoothAngles.x = dest.x - orig.x;
    	smoothAngles.y = dest.y - orig.y;
    	smoothAngles.z = 0.0f;
    	Normalize(smoothAngles);
    	smoothAngles.x = orig.x + smoothAngles.x / 100.0f * smoothAmount;
    	smoothAngles.y = orig.y + smoothAngles.y / 100.0f * smoothAmount;
    	smoothAngles.z = 0.0f;
    	Normalize(smoothAngles);
    	return smoothAngles;
    }

  4. #4
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Code:
    Vector SmoothAngle( const Vector& Src, const Vector& Dst, float SmoothAmount )
    {
    	Vector SmoothedAngles = { 0 };
    	SmoothedAngles.x = Src.x - Dst.x;
    	SmoothedAngles.y = Src.y - Dst.y;
    	SmoothedAngles.z = 0.0f;
    	Normalize( SmoothedAngles);
    
    	SmoothedAngles.x = Src.x - SmoothedAngles.x / SmoothAmount ;
    	SmoothedAngles.y = Src.y - SmoothedAngles.y / SmoothAmount ;
    	SmoothedAngles.z = 0.0f;
    	Normalize( SmoothedAngles);
    
    	return SmoothedAngles;
    }
    Code:
    Vector newAngles = SmoothAngle( ViewAngles, CalculatedAngle, 4.f );
    Last edited by WasserEsser; 07-20-2016 at 09:02 AM.

  5. #5
    samlarenskoog's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    104
    Reputation
    25
    Thanks
    57
    My Mood
    Cheerful
    Quote Originally Posted by WasserEsser View Post
    Code:
    Vector SmoothAngle( const Vector& Src, const Vector& Dst, float SmoothAmount )
    {
    	Vector SmoothedAngles = { 0 };
    	SmoothedAngles.x = Src.x - Dst.x;
    	SmoothedAngles.y = Src.y - Dst.y;
    	SmoothedAngles.z = 0.0f;
    	Normalize( SmoothedAngles);
    
    	SmoothedAngles.x = Src.x - SmoothedAngles.x / SmoothAmount ;
    	SmoothedAngles.y = Src.y - SmoothedAngles.y / SmoothAmount ;
    	SmoothedAngles.z = 0.0f;
    	Normalize( SmoothedAngles);
    
    	return SmoothedAngles;
    }
    Code:
    Vector newAngles = SmoothAngle( ViewAngles, CalculatedAngle, 4.f );
    Now when I shoot it aims up in the air instead, no where particular.

  6. #6
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Quote Originally Posted by samlarenskoog View Post
    Now when I shoot it aims up in the air instead, no where particular.
    And where exactly?

  7. #7
    samlarenskoog's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    104
    Reputation
    25
    Thanks
    57
    My Mood
    Cheerful
    Quote Originally Posted by WasserEsser View Post
    And where exactly?
    maximum pitch and then spins around.

  8. #8
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Quote Originally Posted by samlarenskoog View Post
    maximum pitch and then spins around.
    Post your entire current code.

  9. #9
    samlarenskoog's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    104
    Reputation
    25
    Thanks
    57
    My Mood
    Cheerful
    Quote Originally Posted by WasserEsser View Post
    Post your entire current code.
    Code:
    #include <iostream>
    #include <Windows.h>
    #include <TlHelp32.h>
    #include <random>
    #include <ctime>
    #include <string>
    
    using namespace std;
    
    
    
    
    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;
    const DWORD DwDormant = 0x000000E9;
    
    
    int targetBone = 6;
    int smoothAmount = 40;
    float MinPunch = 1.9f;
    int MaxPunch = 2.0f;
    
    
    typedef struct Vector_
    {
    	float x;
    	float y;
    	float z;
    }Vector;
    
    
    
    void Normalize(Vector& vec);
    
    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));
    		}
    	}
    
    	Vector getVelocity(int playerNumber, DWORD clientDll, HANDLE hProc)
    	{
    		DWORD baseEntity = getEntityBase(hProc, clientDll, playerNumber);
    		if (baseEntity)
    		{
    			return Mem.Read<Vector>(hProc, (baseEntity + DwVecVelocity));
    		}
    	}
    
    	int getFlags(HANDLE hProc, DWORD clientDll, int playerNumber)
    	{
    		DWORD baseEntity = getEntityBase(hProc, clientDll, playerNumber);
    		if (baseEntity)
    		{
    			return Mem.Read<int>(hProc, (baseEntity + DwFlags));
    		}
    	}
    
    	bool radarSpotted(HANDLE hProc, DWORD clientDll, int playerNumber)
    	{
    		DWORD baseEntity = getEntityBase(hProc, clientDll, playerNumber);
    		if (baseEntity)
    		{
    			return Mem.Read<bool>(hProc, (baseEntity + DwSpotted));
    		}
    	}
    
    }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;
    		}
    	}
    
    	void setViewAngle(HANDLE hProc, DWORD engineDll, Vector angles)
    	{
    		DWORD anglePointer = Mem.Read<DWORD>(hProc, (engineDll + DwEnginePointer));
    		if (anglePointer)
    		{
    			Mem.Write<Vector>(hProc, (anglePointer + DwViewAngle), angles);
    		}
    	}
    
    	int getTeam(HANDLE hProc, DWORD clientDll)
    	{
    		DWORD localPlayer = getLocalPlayer(hProc, clientDll);
    		if (localPlayer)
    		{
    			return Mem.Read<int>(hProc, (localPlayer + DwTeamNumber));
    		}
    	}
    
    	Vector getViewOrigin(HANDLE hProc, DWORD clientDll)
    	{
    		DWORD playerBase = getLocalPlayer(hProc, clientDll);
    		if (playerBase)
    		{
    			Vector vecView{};
    			ReadProcessMemory(hProc, (LPCVOID)(playerBase + DwVecViewOrigin), &vecView, sizeof(vecView), NULL);
    			return vecView;
    		}
    	}
    
    	Vector getPosition(HANDLE hProc, DWORD clientDll)
    	{
    		DWORD playerBase = getLocalPlayer(hProc, clientDll);
    		if (playerBase)
    		{
    			return Mem.Read<Vector>(hProc, (playerBase + DwVecOrigin));
    		}
    	}
    
    	Vector getPunch(HANDLE hProc, DWORD clientDll)
    	{
    		DWORD playerBase = getLocalPlayer(hProc, clientDll);
    		if (playerBase)
    		{
    			return Mem.Read<Vector>(hProc, (playerBase + DwVecPunch));
    		}
    	}
    
    	int getShotsFired(HANDLE hProc, DWORD clientDll)
    	{
    		DWORD playerBase = Player.getLocalPlayer(hProc, clientDll);
    		if (playerBase)
    		{
    			return Mem.Read<int>(hProc, (playerBase + DwShotsFired));
    		}
    	}
    
    	Vector getVelocity(DWORD clientDll, HANDLE hProc)
    	{
    		DWORD playerBase = Player.getLocalPlayer(hProc, clientDll);
    		if (playerBase)
    		{
    			return Mem.Read<Vector>(hProc, (playerBase + DwVecVelocity));
    		}
    	}
    
    	int GetLocalIndex(HANDLE hProc, DWORD engineDll) {
    		DWORD dwEngine = Mem.Read<DWORD>(hProc, (engineDll + DwEnginePointer));
    		int localindex = Mem.Read<int>(hProc, (dwEngine + 0x160));
    		return ++localindex;
    	}
    
    	bool SpottedByMe(HANDLE hProc, DWORD engineDll, DWORD clientDll, int p) {
    		int localindex = GetLocalIndex(hProc, engineDll);
    		long dwMask = Mem.Read<long>(hProc, (Entity.getEntityBase(hProc, clientDll, p) + DwSpottedByMask));
    		return bool(dwMask & (1 << (localindex - 1)));
    	}
    
    	Vector getEyePosition(HANDLE hProc, DWORD clientDll)
    	{
    		DWORD playerBase = getLocalPlayer(hProc, clientDll);
    		if (playerBase)
    		{
    			return Mem.Read<Vector>(hProc, (playerBase + vecViewOffset));
    		}
    	}
    
    
    }Player;
    
    Vector CalcAngle(Vector& src, Vector& dst, HANDLE hProc, DWORD clientDll)
    {
    	srand(time(NULL));
    	float Rand = rand() % MaxPunch + MinPunch;
    	Vector vAngle;
    	Vector delta;
    	Vector punch{};
    	punch = Player.getPunch(hProc, clientDll);
    	punch.x *= Rand;
    	punch.y *= Rand;
    	punch.z = 0.0f;
    	Normalize(punch);
    	delta.x = (src.x - dst.x);
    	delta.y = (src.y - dst.y);
    	delta.z = (src.z - dst.z);
    	double hyp = sqrt(delta.x*delta.x + delta.y*delta.y);
    
    	vAngle.x = (float)(atan((delta.z + 64.06f) / hyp) * 57.295779513082f - punch.x);
    	vAngle.y = (float)(atan(delta.y / delta.x) * 57.295779513082f - punch.y);
    	vAngle.z = 0.0f;
    
    	if (delta.x >= 0.0)
    		vAngle.y += 180.0f;
    
    	return vAngle;
    }
    
    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 SmoothAngle(const Vector& Src, const Vector& Dst, float SmoothAmount)
    {
    	Vector SmoothedAngles = { 0 };
    	SmoothedAngles.x = Src.x - Dst.x;
    	SmoothedAngles.y = Src.y - Dst.y;
    	SmoothedAngles.z = 0.0f;
    	Normalize(SmoothedAngles);
    
    	SmoothedAngles.x = Src.x - SmoothedAngles.x / SmoothAmount;
    	SmoothedAngles.y = Src.y - SmoothedAngles.y / SmoothAmount;
    	SmoothedAngles.z = 0.0f;
    	Normalize(SmoothedAngles);
    
    	return SmoothedAngles;
    }
    
    void velocityComp(int playerNumber, HANDLE hProc, DWORD clientDll, Vector& enemyPos)
    {
    	Vector enemyVelocity;
    	Vector myVelocity;
    	enemyVelocity = Entity.getVelocity(playerNumber, clientDll, hProc);
    	myVelocity = Player.getVelocity(clientDll, hProc);
    	enemyPos.x = enemyPos.x + (enemyVelocity.x / 100.f) * (40.f / smoothAmount);
    	enemyPos.y = enemyPos.y + (enemyVelocity.y / 100.f) * (40.f / smoothAmount);
    	enemyPos.z = enemyPos.z + (enemyVelocity.z / 100.f) * (40.f / smoothAmount);
    	enemyPos.x = enemyPos.x - (myVelocity.x / 100.f) * (40.f / smoothAmount);
    	enemyPos.y = enemyPos.y - (myVelocity.y / 100.f) * (40.f / smoothAmount);
    	enemyPos.z = enemyPos.z - (myVelocity.z / 100.f) * (40.f / smoothAmount);
    }
    
    Vector MakeVector(Vector pfin)
    {
    	float pitch = (float)(pfin.x * 57.295779513082f);
    	float yaw = (float)(pfin.y * 57.295779513082f);
    	float tmp = (float)(cos(pitch));
    
    	Vector vector{};
    	vector.x = (float)(-tmp * -cos(yaw));
    	vector.y = (float)(sin(yaw)*tmp);
    	vector.z = (float)(-sin(pitch));
    	Normalize(vector);
    	return vector;
    }
    
    float GetFOV(Vector Angles, Vector Source, Vector Dst, HANDLE hProc, DWORD clientDll)
    {
    	Vector ang{}, aim{};
    	float fov;
    	ang = CalcAngle(Source, Dst, hProc, clientDll);
    	Normalize(ang);
    	aim = MakeVector(Angles);
    	ang = MakeVector(ang);
    
    	float mag_s = sqrt((aim.x * aim.x) + (aim.y * aim.y) + (aim.z * aim.z));
    	float mag_d = sqrt((aim.x * aim.x) + (aim.y * aim.y) + (aim.z * aim.z));
    
    	float u_dot_v = aim.x * ang.x + aim.y * ang.y + aim.z * ang.z;
    	fov = acos(u_dot_v / (mag_s*mag_d)) * (57.295779513082f);
    
    	return fov;
    }
    
    int getClosestToCrosshair(HANDLE hProc, DWORD clientDll, DWORD engineDll)
    {
    
    	float maxFov = 5.f;
    	Vector bonePosition{};
    	int closestEnt = NULL;
    
    	for (int i = 0; i < 32; i++)
    	{
    		DWORD ent = Entity.getEntityBase(hProc, clientDll, i);
    		if (!ent)
    			continue;
    
    		if (ent == Player.getLocalPlayer(hProc, clientDll))
    			continue;
    
    
    		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 localViewAngles = Player.getViewAngle(hProc, engineDll);
    
    		bool isDormant = Mem.Read<bool>(hProc, (ent + DwDormant));
    		int entHealth = Mem.Read<int>(hProc, (ent + DwHealth));
    		Vector bonePosition = Entity.getHeadPos(hProc, clientDll, ent);
    
    		if (isDormant)
    			continue;
    
    		int entitylifestate = Mem.Read<byte>(hProc, ent + 0x0000025B);
    		if (entitylifestate != 0)
    			continue;
    
    
    		if (entHealth > 0 && Entity.getTeam(hProc, clientDll, closestEnt) != Player.getTeam(hProc, clientDll))
    		{
    			float fov = GetFOV(localViewAngles, localPosition, bonePosition, hProc, clientDll);
    			if (fov < maxFov)
    			{
    				maxFov = fov;
    				closestEnt = i;
    
    			}
    		}
    	}
    	return closestEnt;
    }
    
    int main()
    {
    	DWORD pId;
    	bool aimbotOn = false;
    
    	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");
    label1:
    	cin >> aimbotOn;
    	while (true)
    	{
    
    
    		if (aimbotOn)
    		{
    			if (GetAsyncKeyState(0x01) < 0 || GetAsyncKeyState(0x05) < 0)
    			{
    				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.x << endl << viewAngle.y << endl;
    
    				int closestEnt = getClosestToCrosshair(hProc, clientDll, engineDll);
    				Vector headBone = Entity.getHeadPos(hProc, clientDll, closestEnt);
    				Vector vAngle = CalcAngle(localPosition, headBone, hProc, clientDll);
    				Normalize(vAngle);
    
    				cout << vAngle.x << endl << vAngle.y << endl << endl << closestEnt;
    
    
    
    				Vector newAngles = SmoothAngle(viewAngle, vAngle, 4.f);
    				Normalize(newAngles);
    				Player.setViewAngle(hProc, engineDll, newAngles);
    
    
    
    				Sleep(1);
    			}
    			if (GetAsyncKeyState(VK_F1))
    			{
    				cout << "aimbot is off";
    				aimbotOn = false;
    				goto label1;
    			}
    		}
    	}
    	return 0;
    }

  10. #10
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Let's start at the top.

    1.

    Code:
    using namespace std;
    Don't declare a using namespace in global scope, either don't use it at all and prefix the functions you want to use with the namespace or use the using namespace in a certain scope such as a function where you're using the actual namespace.


    2.

    Code:
    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;
    const DWORD DwDormant = 0x000000E9;
    You should look into implementing pattern scanning + clientclass iteration to get offsets dynamically instead of hardcoding them.


    3.

    Code:
    int targetBone = 6;
    int smoothAmount = 40;
    float MinPunch = 1.9f;
    int MaxPunch = 2.0f;
    I dislike global variables as much as possible, you should try to prevent them where ever you can. If you want to store settings, make yourself a neat little settings class and store your settings in the registry and/or in a file.


    4.

    Code:
    typedef struct Vector_
    {
    	float x;
    	float y;
    	float z;
    }Vector;
    By implementing a Vector class ( structs work aswell, but you're using c++ here, classes should be prefered ) you can implement different constructors ( especially a default constructor because your vectors aren't initialized ) aswell as operator overloads. With operator overloads, you don't have to do this each time you want to subtract two vectors:

    Code:
    Vector A = { 0 };
    A.x = B.x - C.x;
    A.y = B.y - C.y;
    A.z = B.z - C.z;
    By the way, you could initialize the vector directly like this:

    Code:
    Vector A = { B.x - C.x, B.y - C.y, B.z - C.z };
    Using operator overloads, you could simplify it even further:

    Code:
    Vector A = B - C;

    5.

    Code:
    void Normalize(Vector& vec);
    That's a function prototype. You declare a function without defining it. That's not necessary in this case, just move the function declaration to the top.


    6.

    Code:
    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;
    You aren't performing any type of error checking here, you just assume that every call to ReadProcessMemory and WriteProcessMemory is succeeding. Also, you're using C++, use classes instead of structs for such things. This isn't a datatype, hence classes are more appropiate.


    7.

    Code:
    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;
    }
    Stay consistent. Sometimes you use sizeof( VariableName ), sometimes you use sizeof( DataType ). Consistency is one of the most valueable things in programming and is one of the things that improve readability by a whole lot. The same goes for your global variables. Why do you have your settings variables global but your handle to the process isn't global? The same goes for the modules base addresses. Stay consistent to increase readability. It would also reduce the amount of parameters for all of your functions aswell as increase performance. Another thing which isn't consistent is your notation. Sometimes you use full caps, sometimes you prefix variable names with their type, sometimes you prefix them with something completely useless, sometimes you use uppercase first, sometimes lowercase.

    You're also not checking if the handle returned by CreateToolhelp32Snapshot is a valid handle, you should check it against INVALID_HANDLE_VALUE.

    You're not calling Module32First, which you should do. It will always be the executable module ( for instance csgo.exe ), but you're using a do while loop, which is totally unnecessary if you're not even calling Module32First. The reason people have been using a do while loop is because it's condition is checked at the end of the loop, allowing for a call to Module32First at the start without an if statement for it. The overall control flow of the function is better this way.

    This thread is covering process iteration, but it's the same for modules:

    https://www.mpgh.net/forum/showthread.php?t=1128046


    8.

    Code:
    struct
    {
    I said it already, don't use structs for such things in C++. Apart from this, you have two different structs, one for enemy players and one for your own player. You are obviously a player aswell as your enemy. You and the enemy have the same inhertience structure aswell as the same variables, there is no need to create two different structs ( hopefully classes soon. ). You can combine them into one datastructure.


    9.

    Code:
    DWORD getEntityBase(HANDLE hProc, DWORD clientDll, int playerNumber)
    {
    	return Mem.Read<DWORD>(hProc, (clientDll + DwEntityList + (DwEntitySize * (playerNumber - 1))));
    }
    If you're using playerNumber - 1 you might aswell just use the right offset for the entitylist instead of subtracting one. The right offset is the offsets that usual dumpers give you - 0x10.


    10.

    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;
    		}
    	}
    }
    You are not specifying a value to return when either entityBase or boneMatrix are nullptrs. You should return a default vector with values initialized as 0.

    You can read the bone structure in one call, removing unnecessary overhead. Make a small struct, pad it correctly and return a vector out of the bone coordinates.


    11.

    Code:
    int getTeam(HANDLE hProc, DWORD clientDll, int playerNumber)
    {
    	DWORD entityBase = getEntityBase(hProc, clientDll, playerNumber);
    	if (entityBase)
    	{
    		return Mem.Read<int>(hProc, (entityBase + DwTeamNumber));
    	}
    }
    Here aswell, you aren't specifying a value to return when entityBase is a nullptr. I'm kind of surprised your compiler didn't warn you about it.


    12.

    Code:
    int getHealth(HANDLE hProc, DWORD clientDll, int playerNumber)
    {
    	DWORD entityBase = getEntityBase(hProc, clientDll, playerNumber);
    	if (entityBase)
    	{	
    		return Mem.Read<int>(hProc, (entityBase + DwHealth));
    	}
    }
    
    Vector getVelocity(int playerNumber, DWORD clientDll, HANDLE hProc)
    {
    	DWORD baseEntity = getEntityBase(hProc, clientDll, playerNumber);
    	if (baseEntity)
    	{
    		return Mem.Read<Vector>(hProc, (baseEntity + DwVecVelocity));
    	}
    }
    
    int getFlags(HANDLE hProc, DWORD clientDll, int playerNumber)
    {
    	DWORD baseEntity = getEntityBase(hProc, clientDll, playerNumber);
    	if (baseEntity)
    	{
    		return Mem.Read<int>(hProc, (baseEntity + DwFlags));
    	}
    }
    
    bool radarSpotted(HANDLE hProc, DWORD clientDll, int playerNumber)
    {
    	DWORD baseEntity = getEntityBase(hProc, clientDll, playerNumber);
    	if (baseEntity)
    	{
    		return Mem.Read<bool>(hProc, (baseEntity + DwSpotted));
    	}
    }
    Read #11.


    13.

    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;
    	}
    }
    Read #11. If you initialize your vector as above, the default constructor is getting called. Since you don't have a default constructor, it will use a compiler generated constructor which isn't going to initialize your variables. Consider initializing them like this:

    Code:
    Vector angles { 0 };
    This will default initialize each member to 0. This also prevents you from not being able to move your mouse anymore and your viewangles being locked at 0 as shown in the video above. The numbers you were trying to set weren't floating point numbers, default initialization to 0 will prevent that.


    14.

    Code:
    Vector getViewOrigin(HANDLE hProc, DWORD clientDll)
    {
    	DWORD playerBase = getLocalPlayer(hProc, clientDll);
    	if (playerBase)
    	{
    		Vector vecView{};
    		ReadProcessMemory(hProc, (LPCVOID)(playerBase + DwVecViewOrigin), &vecView, sizeof(vecView), NULL);
    		return vecView;
    	}
    }
    Read #11. Consistency my friend. You're randomly using raw a ReadProcessMemory call here for no reason while everywhere else you're using your Mem struct ( make it a class please ).


    15.

    Code:
    Vector getPosition(HANDLE hProc, DWORD clientDll)
    {
    	DWORD playerBase = getLocalPlayer(hProc, clientDll);
    	if (playerBase)
    	{
    		return Mem.Read<Vector>(hProc, (playerBase + DwVecOrigin));
    	}
    }
    
    Vector getPunch(HANDLE hProc, DWORD clientDll)
    {
    	DWORD playerBase = getLocalPlayer(hProc, clientDll);
    	if (playerBase)
    	{
    		return Mem.Read<Vector>(hProc, (playerBase + DwVecPunch));
    	}
    }
    
    int getShotsFired(HANDLE hProc, DWORD clientDll)
    {
    	DWORD playerBase = Player.getLocalPlayer(hProc, clientDll);
    	if (playerBase)
    	{
    		return Mem.Read<int>(hProc, (playerBase + DwShotsFired));
    	}
    }
    
    Vector getVelocity(DWORD clientDll, HANDLE hProc)
    {
    	DWORD playerBase = Player.getLocalPlayer(hProc, clientDll);
    	if (playerBase)
    	{
    		return Mem.Read<Vector>(hProc, (playerBase + DwVecVelocity));
    	}
    }
    Read #11.


    16.

    Code:
    int GetLocalIndex(HANDLE hProc, DWORD engineDll) {
    	DWORD dwEngine = Mem.Read<DWORD>(hProc, (engineDll + DwEnginePointer));
    	int localindex = Mem.Read<int>(hProc, (dwEngine + 0x160));
    	return ++localindex;
    }
    The offset is wrong. It's 0x178. Why do you return ++localinddex when you later on in SpottedByMe subtract one? That's completely redundant.


    17.

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


    18.

    Code:
    Vector CalcAngle(Vector& src, Vector& dst, HANDLE hProc, DWORD clientDll)
    {
    	srand(time(NULL));
    	float Rand = rand() % MaxPunch + MinPunch;
    	Vector vAngle;
    	Vector delta;
    	Vector punch{};
    	punch = Player.getPunch(hProc, clientDll);
    	punch.x *= Rand;
    	punch.y *= Rand;
    	punch.z = 0.0f;
    	Normalize(punch);
    	delta.x = (src.x - dst.x);
    	delta.y = (src.y - dst.y);
    	delta.z = (src.z - dst.z);
    	double hyp = sqrt(delta.x*delta.x + delta.y*delta.y);
    
    	vAngle.x = (float)(atan((delta.z + 64.06f) / hyp) * 57.295779513082f - punch.x);
    	vAngle.y = (float)(atan(delta.y / delta.x) * 57.295779513082f - punch.y);
    	vAngle.z = 0.0f;
    
    	if (delta.x >= 0.0)
    		vAngle.y += 180.0f;
    
    	return vAngle;
    }
    Holy damn. This is utterly bullshit and shouldn't be used by anyone. It's old paste. delta.z + 64.06f already indicates that it has been used before people were able to get the position of people's head. Also don't compensate for punch in your CalcAngle function. Just do it outside to improve readability.

    The hypotenuse is also not correctly calculated, you're using 3d vectors here, the z components are missing.

    Changed it up a bit:

    Code:
    Vector CalcAngle( const Vector& src, const Vector& dst )
    {
    	Vector delta { 0 };
    	Vector vAngle { 0 };
    	delta.x = ( src.x - dst.x );
    	delta.y = ( src.y - dst.y );
    	delta.z = ( src.z - dst.z );
    	double hyp = sqrt( delta.x * delta.x + delta.y * delta.y + delta.z * delta.z );
    
    	vAngle.x = ( float )( atan( delta.z / hyp ) * 57.295779513082f );
    	vAngle.y = ( float )( atan( delta.y / delta.x ) * 57.295779513082f );
    	vAngle.z = 0.0f;
    
    	if ( delta.x >= 0.0 )
    		vAngle.y += 180.0f;
    
    	return vAngle;
    }

    19.

    Code:
    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;
    }
    Grrr. I told you to NOT clamp inside your normalize function. I feel like im talking against a wall. Seperate normalize with clamping.

    Code:
    void NormalizeAngles( Vector& v )
    {
    	if ( !std::isfinite( v.x ) ) v.x = 0.f;
    	if ( !std::isfinite( v.y ) ) v.y = 0.f;
    	if ( !std::isfinite( v.z ) ) v.z = 0.f;
    
    	v.x = std::remainder( v.x, 360.f );
    	v.y = std::remainder( v.y, 360.f );
    	v.z = std::remainder( v.z, 360.f );
    }
    
    void ClampAngles( Vector& v )
    {
    	v.x = std::max( -89.f, std::min( 89.f, v.x ) );
    	v.z = std::max( -50.f, std::min( 50.f, v.z ) );
    }

    20.

    Code:
    void velocityComp(int playerNumber, HANDLE hProc, DWORD clientDll, Vector& enemyPos)
    {
    	Vector enemyVelocity;
    	Vector myVelocity;
    	enemyVelocity = Entity.getVelocity(playerNumber, clientDll, hProc);
    	myVelocity = Player.getVelocity(clientDll, hProc);
    	enemyPos.x = enemyPos.x + (enemyVelocity.x / 100.f) * (40.f / smoothAmount);
    	enemyPos.y = enemyPos.y + (enemyVelocity.y / 100.f) * (40.f / smoothAmount);
    	enemyPos.z = enemyPos.z + (enemyVelocity.z / 100.f) * (40.f / smoothAmount);
    	enemyPos.x = enemyPos.x - (myVelocity.x / 100.f) * (40.f / smoothAmount);
    	enemyPos.y = enemyPos.y - (myVelocity.y / 100.f) * (40.f / smoothAmount);
    	enemyPos.z = enemyPos.z - (myVelocity.z / 100.f) * (40.f / smoothAmount);
    }
    This one has to be rewritten due to the new smooth function.


    21.

    Code:
    Vector MakeVector(Vector pfin)
    {
    	float pitch = (float)(pfin.x * 57.295779513082f);
    	float yaw = (float)(pfin.y * 57.295779513082f);
    	float tmp = (float)(cos(pitch));
    
    	Vector vector{};
    	vector.x = (float)(-tmp * -cos(yaw));
    	vector.y = (float)(sin(yaw)*tmp);
    	vector.z = (float)(-sin(pitch));
    	Normalize(vector);
    	return vector;
    }
    Why do you even have that in your code? It's not needed.


    22.

    Code:
    float GetFOV(Vector Angles, Vector Source, Vector Dst, HANDLE hProc, DWORD clientDll)
    {
    	Vector ang{}, aim{};
    	float fov;
    	ang = CalcAngle(Source, Dst, hProc, clientDll);
    	Normalize(ang);
    	aim = MakeVector(Angles);
    	ang = MakeVector(ang);
    
    	float mag_s = sqrt((aim.x * aim.x) + (aim.y * aim.y) + (aim.z * aim.z));
    	float mag_d = sqrt((aim.x * aim.x) + (aim.y * aim.y) + (aim.z * aim.z));
    
    	float u_dot_v = aim.x * ang.x + aim.y * ang.y + aim.z * ang.z;
    	fov = acos(u_dot_v / (mag_s*mag_d)) * (57.295779513082f);
    
    	return fov;
    }
    Why don't you just simply use the magnitude between two vectors?

    Code:
    float GetFOV( const Vector& Src, const Vector& Dst )
    {
    	Vector Delta = { Src.x - Dst.x, Src.y - Dst.y, Src.z - Dst.z }; // Vector Delta = Src - Dst; with operator overloads
    	Normalize( Delta );
    	return sqrt( Delta.x * Delta.x + Delta.y * Delta.y + Delta.z * Delta.z );
    }

    23.

    Code:
    int getClosestToCrosshair(HANDLE hProc, DWORD clientDll, DWORD engineDll)
    {	
    	float maxFov = 5.f;
    	Vector bonePosition{};
    	int closestEnt = NULL;
    
    	for (int i = 0; i < 32; i++)
    	{
    		DWORD ent = Entity.getEntityBase(hProc, clientDll, i);
    		if (!ent)
    			continue;
    
    		if (ent == Player.getLocalPlayer(hProc, clientDll))
    			continue;
    
    
    		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 localViewAngles = Player.getViewAngle(hProc, engineDll);
    
    		bool isDormant = Mem.Read<bool>(hProc, (ent + DwDormant));
    		int entHealth = Mem.Read<int>(hProc, (ent + DwHealth));
    		Vector bonePosition = Entity.getHeadPos(hProc, clientDll, ent);
    
    		if (isDormant)
    			continue;
    
    		int entitylifestate = Mem.Read<byte>(hProc, ent + 0x0000025B);
    		if (entitylifestate != 0)
    			continue;
    
    
    		if (entHealth > 0 && Entity.getTeam(hProc, clientDll, closestEnt) != Player.getTeam(hProc, clientDll))
    		{
    			float fov = GetFOV(localViewAngles, localPosition, bonePosition, hProc, clientDll);
    			if (fov < maxFov)
    			{
    				maxFov = fov;
    				closestEnt = i;
    
    			}
    		}
    	}
    	return closestEnt;
    }
    You've done a few things wrong here. First you should use a much higher value than 5 for maxfov to begin with. Use something like 99999.f;. the bonePosition vector is not initialized, which you should do ( you can do it in the constructor ) as said above.

    Code:
    int closestEnt = NULL;
    Should at best be a value like -1, then you know if you actually mean the entity 0 or if the function just didn't find any entities. You can later on filter for -1 and not aim if no entity was found.

    Code:
    for (int i = 0; i < 32; i++)
    Counter-Strike: Global Offensive can have 64 players on one server, use 64 instead. Your loop also starts at 0, since you do id - 1 in your getEntityBase function, you're essentially ending up with the world entity instead.

    I've already talked about initialization, so i won't cover it again. I also talked about operator overloads.


    24.

    Code:
    int main()
    {
    	DWORD pId;
    	bool aimbotOn = false;
    
    	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");
    label1:
    	cin >> aimbotOn;
    	while (true)
    	{
    
    
    		if (aimbotOn)
    		{
    			if (GetAsyncKeyState(0x01) < 0 || GetAsyncKeyState(0x05) < 0)
    			{
    				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.x << endl << viewAngle.y << endl;
    
    				int closestEnt = getClosestToCrosshair(hProc, clientDll, engineDll);
    				Vector headBone = Entity.getHeadPos(hProc, clientDll, closestEnt);
    				Vector vAngle = CalcAngle(localPosition, headBone, hProc, clientDll);
    				Normalize(vAngle);
    
    				cout << vAngle.x << endl << vAngle.y << endl << endl << closestEnt;
    
    
    
    				Vector newAngles = SmoothAngle(viewAngle, vAngle, 4.f);
    				Normalize(newAngles);
    				Player.setViewAngle(hProc, engineDll, newAngles);
    
    
    
    				Sleep(1);
    			}
    			if (GetAsyncKeyState(VK_F1))
    			{
    				cout << "aimbot is off";
    				aimbotOn = false;
    				goto label1;
    			}
    		}
    	}
    	return 0;
    }
    Code:
    label1:
    goto label1;
    Please don't use goto, use proper control flow instead.

    Code:
    if (GetAsyncKeyState(0x01) < 0 || GetAsyncKeyState(0x05) < 0)
    As said many times aswell, check for GetAsyncKeyState( KEY ) & ( 1 << 15 ) instead of < 0.

    Read the documentation for more info:

    https://msdn.microsof*****m/en-en/lib...(v=vs.85).aspx

    Don't forget to check for -1 after you called the getClosestToCrosshair function.

  11. The Following 4 Users Say Thank You to WasserEsser For This Useful Post:

    gogogokitty (09-30-2018),Hunter (07-26-2016),samlarenskoog (07-20-2016),Smoke (07-20-2016)

  12. #11
    Smoke's Avatar
    Join Date
    Nov 2014
    Gender
    male
    Posts
    11,899
    Reputation
    2661
    Thanks
    4,610
    My Mood
    Amazed
    It seems this has been solved.

    /Closed.


    CLICK TO BUY NOW!!


    Quote Originally Posted by Liz View Post
    This is my first vouch, ever. Rapidgator account worked perfectly. Would buy in the future.

Similar Threads

  1. [Help] Can't get ID of enemy in crosshair
    By xeyerericx in forum Counter-Strike 2 Coding & Resources
    Replies: 11
    Last Post: 01-27-2016, 04:03 PM
  2. [Help] Detect enemy in crosshair through smoke?
    By coderus in forum Counter-Strike 2 Coding & Resources
    Replies: 5
    Last Post: 10-03-2015, 07:30 PM
  3. Advice on getting closest to 60% max on enchanting
    By fleepies in forum Vindictus Help
    Replies: 6
    Last Post: 04-05-2012, 01:40 AM
  4. Crosshair Fail...
    By Dark Butters in forum Combat Arms Mod Discussion
    Replies: 4
    Last Post: 08-29-2010, 09:32 AM