HelpInternal aimbot crash

Posts 1–3 of 3 · Page 1 of 1
Internal aimbot crash
I'm trying to make an internal aimbot using MarkHC's base and I'm having some issues with crashing as soon as a bullet is shot.

Aimbot class
Code:
#define PI 3.14159265358979323846f
#include "main.h"

class Aimbot {
private:
	C_CSPlayer* pLocal;
	SourceEngine::Vector vecAimBone;

	float VectorNormalize(SourceEngine::Vector& v)
	{
		float flLength = v.Length();
		if (!flLength)
			v.Init();
		else
			v /= flLength;

		return flLength;
	}

	void ClampAngles(SourceEngine::Vector& v)
	{
		if (v.x > 89.0f && v.x <= 180.0f)
			v.x = 89.0f;

		if (v.x > 180.0f)
			v.x = v.x - 360.0f;

		if (v.x < -89.0f)
			v.x = -89.0f;

		v.y = fmodf(v.y + 180, 360) - 180;

		v.z = 0;
	}

	void CalcAngle(SourceEngine::Vector &src, SourceEngine::Vector &dst, SourceEngine::QAngle &angles)
	{
		SourceEngine::QAngle delta = SourceEngine::QAngle((src[0] - dst[0]), (src[1] - dst[1]), (src[2] - dst[2]));
		double hyp = sqrtf(delta[0] * delta[0] + delta[1] * delta[1]);
		angles[0] = atan(delta[2] / hyp)        *(180.0 / PI);
		angles[1] = atan(delta[1] / delta[0])    *(180.0 / PI);
		angles[2] = 0.0f;
		if (delta[0] >= 0.0) { angles[1] += 180.0f; }
	}


	void MakeVector(SourceEngine::QAngle angle, SourceEngine::QAngle& vector)
	{
		float pitch = float(angle[0] * PI / 180);
		float yaw = float(angle[1] * PI / 180);
		float tmp = float(cos(pitch));
		vector[0] = float(-tmp * -cos(yaw));
		vector[1] = float(sin(yaw)*tmp);
		vector[2] = float(-sin(pitch));
	}



	float GetFov(SourceEngine::QAngle angle, SourceEngine::Vector src, SourceEngine::Vector dst)
	{
		SourceEngine::QAngle ang, aim;
		float fov;

		CalcAngle(src, dst, ang);
		MakeVector(angle, aim);
		MakeVector(ang, ang);

		float mag_s = sqrt((aim[0] * aim[0]) + (aim[1] * aim[1]) + (aim[2] * aim[2]));
		float mag_d = sqrt((aim[0] * aim[0]) + (aim[1] * aim[1]) + (aim[2] * aim[2]));

		float u_dot_v = aim[0] * ang[0] + aim[1] * ang[1] + aim[2] * ang[2];

		fov = acos(u_dot_v / (mag_s*mag_d)) * (180.0 / PI);

		return fov;
	}

	bool IsVisible(SourceEngine::Vector& vecAbsStart, SourceEngine::Vector& vecAbsEnd, SourceEngine::IClientEntity* pLocal, SourceEngine::IClientEntity* pBaseEnt)
	{
		SourceEngine::trace_t tr;
		SourceEngine::Ray_t ray;
		SourceEngine::CTraceFilter filter;

		filter.pSkip = pLocal;
		ray.Init(vecAbsStart, vecAbsEnd);

		SourceEngine::Interfaces::EngineTrace()->TraceRay(ray, 0x46004003, &filter, &tr);

		return (tr.m_pEnt == pBaseEnt || tr.fraction > 0.99f);
	}

	SourceEngine::Vector CalcAngle(SourceEngine::Vector src, SourceEngine::Vector dst)
	{
		SourceEngine::Vector angles;
		double delta[3] = { (src[0] - dst[0]), (src[1] - dst[1]), (src[2] - dst[2]) };
		double hyp = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
		angles[0] = (float)(asinf(delta[2] / hyp) * 57.295779513082f);
		angles[1] = (float)(atanf(delta[1] / delta[0]) * 57.295779513082f);
		angles[2] = 0.0f;
		if (delta[0] >= 0.0) { angles[1] += 180.0f; }
		return angles;
	}

	static SourceEngine::Vector GetEntityBone(SourceEngine::IClientEntity* pEntity, SourceEngine::ECSPlayerBones Bone)
	{
		SourceEngine::matrix3x4_t boneMatrix[128];

		if (!pEntity->SetupBones(boneMatrix, 128, 0x00000100, SourceEngine::Interfaces::Engine()->GetLastTimeStamp()))
			return SourceEngine::Vector();

		SourceEngine::matrix3x4_t hitbox = boneMatrix[Bone];

		return SourceEngine::Vector(hitbox[0][3], hitbox[1][3], hitbox[2][3]);
	}


public:

	Aimbot() {
		pLocal = C_CSPlayer::GetLocalPlayer();
	}

	void Aim(SourceEngine::CUserCmd* pCmd) {
		SourceEngine::Vector vecLocalEyePos = pLocal->GetEyePos();

		VectorNormalize(vecLocalEyePos); 

										
		for (int i = 1; i < SourceEngine::Interfaces::Engine()->GetMaxClients(); i++) {

	
			if (i == SourceEngine::Interfaces::Engine()->GetLocalPlayer())
				continue;

			auto pEntity = static_cast<C_CSPlayer*>(SourceEngine::Interfaces::EntityList()->GetClientEntity(i));

			
			if (!pEntity) {
				continue;
			}
			
			if (pEntity->GetTeamNum() == pLocal->GetTeamNum()) {
				continue;
			}
			
			if (!pEntity->IsAlive() || pEntity->GetHealth() > 500 || pEntity->IsDormant()) {
				continue;
			}

			vecAimBone = GetEntityBone(pEntity, SourceEngine::ECSPlayerBones::head_0);

			if ((GetFov(pCmd->viewangles, pLocal->GetEyePos(), vecAimBone) > Options::g_fRCSFOV)) {
				continue;
			}

			D3DXVECTOR3 tmp;
			tmp.x = vecAimBone.x;
			tmp.y = vecAimBone.y;
			tmp.z = vecAimBone.z;

			if (IsVisible(pLocal->GetEyePos(), vecAimBone, pLocal, pEntity))
			{
				SourceEngine::QAngle qAimAngles = CalcAngle(vecLocalEyePos, vecAimBone);
				SourceEngine::Vector vAim = SourceEngine::Vector(qAimAngles.x, qAimAngles.y, 0);
				ClampAngles(vAim);
				pCmd->viewangles = vAim;
			}

		}
	}
};
CreateMove
Code:
bool __stdcall Hooked_CreateMove(float sample_input_frametime, SourceEngine::CUserCmd* pCmd) {

		bool bRet = g_fnOriginalCreateMove(SourceEngine::Interfaces::ClientMode(), sample_input_frametime, pCmd);	
		
		if (SourceEngine::Interfaces::Engine()->IsInGame() && Options::g_bRCSEnabled) {	

			Aimbot gaybot;
		
			gaybot.Aim(pCmd);
	
		}
		
		return bRet;
	}
@CLOOK, you can only bump your thread once every 24 hours.
1 week has passed and no further replies have been made by the OP. Assuming solved.

/Closed.
Posts 1–3 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Talk with us