All pastes #553402 Raw Edit

Stuff

public text v1 · immutable
·published 2007-06-09 18:28 UTC
rendered paste body
// GPL License - see http://opensource.org/licenses/gpl-license.php
// Copyright 2006 *nixCoders team - don't forget to credit 
#include "nex.h"
#include <iostream>
#include "phax.h"
CnexAimbot nexAimbot;

typedef enum {
	HITBOX_OFF,
	HITBOX_ETPRO,
	HITBOX_ETMAIN,
	HITBOX_ETPUB_REALHEAD,
	HITBOX_ETPUB_UNFIXED,
	HITBOX_GENERAL,
	
	HITBOX_TOTAL
} hitbox_t;

// for hitbox correction
typedef enum {
	STANDING,
	CROUCH,
	PRONE,

 	MAX_HITBOX_STATE
} HitboxState_t;
typedef struct {
	float x;
	float y;
	float z;
} vec3_union;



vec3_union hitboxDef[HITBOX_TOTAL][MAX_HITBOX_STATE];

void fillHitboxCorrection() {
	hitboxDef[HITBOX_ETPRO][STANDING] = (vec3_union) {-1.0, 0.0, 6.5;};
	hitboxDef[HITBOX_ETPRO][CROUCH] = (vec3_union){-1.0, 0.0, 6.5;};
	hitboxDef[HITBOX_ETPRO][PRONE] = (vec3_union){1.5, -1.0, 6.5;};

	hitboxDef[HITBOX_ETMAIN][STANDING] = (vec3_union){0.0, 0.0, 4.0;};
	hitboxDef[HITBOX_ETMAIN][CROUCH] = (vec3_union){0.0, 0.0, 4.0;};
	hitboxDef[HITBOX_ETMAIN][PRONE] = (vec3_union){0.0, 0.0, 4.0;};

	hitboxDef[HITBOX_ETPUB_REALHEAD][STANDING] = (vec3_union){1.0, -1.0, 6.5;};
	hitboxDef[HITBOX_ETPUB_REALHEAD][CROUCH] = (vec3_union){1.0, -1.0, 6.5;};
	hitboxDef[HITBOX_ETPUB_REALHEAD][PRONE] = (vec3_union){2.0, 0.0, 6.5;};

	hitboxDef[HITBOX_ETPUB_UNFIXED][STANDING] = (vec3_union){0.0, 0.0, 4.0};
	hitboxDef[HITBOX_ETPUB_UNFIXED][CROUCH] = (vec3_union){0.0, 0.0, 4.0};
	hitboxDef[HITBOX_ETPUB_UNFIXED][PRONE] = (vec3_union){0.0, 0.0, 4.0};

	hitboxDef[HITBOX_GENERAL][STANDING] = (vec3_union){0.5, 0.0, 6.5};
	hitboxDef[HITBOX_GENERAL][CROUCH] = (vec3_union){0.5, 0.0, 6.5};
	hitboxDef[HITBOX_GENERAL][PRONE] = (vec3_union){0.5, 0.0, 6.5;};
}
void CnexAimbot::blockMouse(bool state) {
	if (!bot_blockmouse.integer)
		return;

	#define SENSITIVITY_STR "sensitivity"
	static float sensitivity = 0;	// For backup user sensitivity
	static bool mouseBlocked = false;	// Current state
	char buffer[32];

	// Set sensitivity
	if (state && !mouseBlocked) {
		nexSyscall.Cvar_VariableStringBuffer(SENSITIVITY_STR, buffer, sizeof(buffer));
		sensitivity = atof(buffer);

		nexSyscall.SendConsoleCommand(SENSITIVITY_STR " 0\n");
		mouseBlocked = qtrue;
	} else if (!state && mouseBlocked) {
		sprintf_s(buffer, sizeof(buffer), SENSITIVITY_STR " %f\n", sensitivity);
		nexSyscall.SendConsoleCommand(buffer);
		mouseBlocked = false;

	}
					
}







static char *modelBodyTags[] = {
	"tag_chest",
	"tag_torso",
	"tag_bright",
	"tag_lbelt",
	"tag_bleft",
	"tag_ubelt",
	"tag_back",
	"tag_armleft",
	"tag_weapon",
	"tag_armright",
	"tag_weapon2",
	"tag_legright",
	"tag_legleft",
	"tag_footleft",
	"tag_footright"
};
void aimbotUpCommand (void) {}
void CnexAimbot::snapshotPredict( int player ){
	snapPredict_t history[MAX_CLIENTS][3];
	vec3_t va;
	float dt;
	int curTime = orig_syscall( CG_MILLISECONDS );	
	if( (curTime - (int) history[player][0].t)  > 150  || !history[player][1].t || !history[player][2].t ){
		memset( history[player][0].prPos, 0, sizeof(vec3_t));
		return;
	}
	dt = 1000.0 / (history[player][0].t - history[player][1].t);
	va[0] = (history[player][0].trPos[0] - history[player][1].trPos[0])*dt;
	va[1] = (history[player][0].trPos[1] - history[player][1].trPos[1])*dt;
	va[2] = (history[player][0].trPos[2] - history[player][1].trPos[2])*dt;
	history[player][0].prTime = (curTime - history[player][2].t)/333.3;
	VectorCopy(va, history[player][0].prPos );
}


void CnexAimbot::aimAt(vec3_t target) {
	vec3_t org, ang;
	if (bot_enemyprediction.value == 3) {
		vec3_t pVieworg;
		VectorMA(nex.cg_refdef.vieworg, (float)(nex.cg_frametime) / 1000.0f, nex.cg_entities[nex.cg_clientNum].currentState->pos.trDelta, pVieworg);
		VectorSubtract(target, pVieworg, org);
    } else {
		VectorSubtract(target, nex.cg_refdef.vieworg, org);
	}
	vectoangles(org, ang);
	ang[PITCH] -= nex.cg_refdefViewAngles[PITCH];
	ang[YAW] -= nex.cg_refdefViewAngles[YAW];																											
if (bot_human.integer) {
        while (ang[PITCH] < -360.0f)
            ang[PITCH] += 360.0f;
        while (ang[PITCH] > 360.0f)
            ang[PITCH] -= 360.0f;
        while (ang[YAW] < -360.0f)
            ang[YAW] += 360.0f;
        while (ang[YAW] > 360.0f)
            ang[YAW] -= 360.0f;
        if (ang[PITCH] > 180.0f)
            ang[PITCH] -= 360.0f;
        if (ang[PITCH] < -180.0f)
            ang[PITCH] += 360.0f;
        if (ang[YAW] > 180.0f)
            ang[YAW] -= 360.0f;
        if (ang[YAW] < -180.0f)
            ang[YAW] += 360.0f;
    float aimDiv = bot_divmax.value;
        if (aimDiv>(float)(bot_divmin.value)) {
        ang[PITCH] *= bot_humanvalue.value/aimDiv;
        ang[YAW] *= bot_humanvalue.value/aimDiv;
        aimDiv -= bot_humanvalue.value;
        } else
            {
                aimDiv = (float)(bot_divmax.value);
            }
    }
    *(float *)snex.ET->cl_mouseDy += ang[PITCH];
    *(float *)snex.ET->cl_mouseDx += ang[YAW];
}


bool CnexAimbot::getVisibleModelBodyTag(const int player, vec3_t *origin) {
	int count = 0;
	for (; count < (sizeof(modelBodyTags) / sizeof(char *)); count++) {
		char *tagText = modelBodyTags[count];
		orientation_t tagOrientation;
		if (!CG_GetTag(player, tagText, &tagOrientation)) {
			return false;
		}
		if (nexEngine.isVisible(tagOrientation.origin, NULL, NULL )) {
			VectorCopy(tagOrientation.origin, *origin);
			return true;
		}	
	}
	return false;
}

bool CnexAimbot::CG_GetTag(int clientNum, char *tagname, orientation_t *or) {
	nex_centity_t	*cent;
	refEntity_t		*refent;
	vec3_t			tempAxis[3];
	vec3_t			org;
	int				i;
	cent = &nex.cg_entities[clientNum];
	if (!cent->currentValid)
		return false;		
	refent = &nex.cg_entities[clientNum].pe_bodyRefEnt;
	if (nexSyscall.R_LerpTag(or, refent, tagname, 0 ) < 0)
		return false;
	VectorCopy(nex.entities[clientNum].origin, org);
	for (i = 0 ; i < 3 ; i++)
		VectorMA(org, or->origin[i], refent->axis[i], org);
	VectorCopy(org, or->origin);
	MatrixMultiply(refent->axis, or->axis, tempAxis);
	memcpy(or->axis, tempAxis, sizeof(vec3_t) * 3);
	return true;
}
void CnexAimbot::doAutoShoot(bool shoot) {if (bot_auto.integer){
	if (nex.cg_clientNum != nex.cg_snap->ps.clientNum)
		return;
	if (shoot) {
		if (((nex.cg_entities[nex.cg_clientNum].currentState->weapon == WP_K43_SCOPE) || (nex.cg_entities[nex.cg_clientNum].currentState->weapon == WP_GARAND_SCOPE)) && !BG_PlayerMounted(nex.cg_snap->ps.eFlags)) {
			static int lastShootTime = 0;
			if ((nex.cg_time - lastShootTime) >= bot_sniperdelay.value) {
				nexSyscall.SendConsoleCommand("+attack\n");
				lastShootTime = nex.cg_time;
			} else {
				nexSyscall.SendConsoleCommand("-attack\n");
			}
		} else if (bot_burst.integer && (nex.cg_snap->ps.curWeapHeat > bot_burstlimit.value)) {
			nexSyscall.SendConsoleCommand("-attack\n");
		} else {
			nexSyscall.SendConsoleCommand("+attack\n");
		}
	} else {
		nexSyscall.SendConsoleCommand("-attack\n");
	}
}}


int CnexAimbot::findNearestTarget(int targetFlag) {
	int nearest = -1;
	int maxEntities = MAX_GENTITIES;
	if (targetFlag & TARGET_PLAYER)
		maxEntities = MAX_CLIENTS;
	int entityNum = 0;
	if( (bot_priority.value == 1 ) ){
		int ent = nex.cg_snap->ps.persistant[PERS_ATTACKER];
		if( ent && ent <= MAX_CLIENTS ){
			if( ((targetFlag & TARGET_ENEMY) && (targetFlag & TARGET_PLAYER) && IS_PLAYER_ENEMY(entityNum))
				&& nex.entities[ent].isVisible && !IS_PLAYER_DEAD(ent) )
				return ent;
		}
	}
	for (; entityNum < MAX_CLIENTS; entityNum++) {
		nexEntity_t* entity = &nex.entities[entityNum];
		if (!nex.cg_entities[entityNum].currentValid || (entityNum == nex.cg_snap->ps.clientNum) || !nex.client[entityNum].infoValid)
			continue;
		if ((targetFlag & TARGET_PLAYER) && !IS_PLAYER_VALID(entityNum))
			continue;
		if ((targetFlag & TARGET_PLAYER_VULN) && !IS_PLAYER_VULNERABLE(entityNum))
			continue;
		if ((targetFlag & TARGET_PLAYER_ALIVE) && IS_PLAYER_DEAD(entityNum))
			continue;
		if ((targetFlag & TARGET_PLAYER_DEAD) && !IS_PLAYER_DEAD(entityNum))
			continue;
		if ((targetFlag & TARGET_PLAYER_HEAD) && !entity->isHeadVisible)
			continue;
		if ((targetFlag & TARGET_PLAYER_BODY) && VectorCompare(entity->bodyPart, vec3_origin))
			continue;
		if ( (targetFlag & TARGET_VISIBLE) && entity->isVisible &&
			(bot_priority.value==2) && nex.clAttack[entityNum] )
			return entityNum;
		if ((targetFlag & TARGET_ENEMY) && !IS_PLAYER_ENEMY(entityNum))
			continue;
		if ((targetFlag & TARGET_FRIEND) && IS_PLAYER_ENEMY(entityNum))
			continue;
		if ((targetFlag & TARGET_VISIBLE) && !entity->isVisible)
			continue;
		if ((targetFlag & TARGET_NOTVISIBLE) && entity->isVisible)
			continue;
		if( (bot_priority.value == 3) && IS_PANZER(entityNum) )
			return entityNum;
		if( (bot_priority.value == 4) && IS_MG42(entityNum) )
			return entityNum;
		if( (bot_priority.value == 5) && IS_HEAVYWP(entityNum) )
			return entityNum;
		float aimfov = AngleNormalize360(bot_fov.value);
		if (aimfov) {
			vec3_t aimPoint, ang, org;
			if (nex.entities[entityNum].isHeadVisible)
				VectorCopy(nex.entities[entityNum].head, aimPoint);
			else if (!bot_headaim.integer)
				VectorCopy(nex.entities[entityNum].bodyPart, aimPoint);
			else {
				return -1;
			}
			VectorSubtract(aimPoint, nex.cg_refdef.vieworg, org);
			vectoangles(org, ang);
			ang[PITCH] -= nex.cg_refdefViewAngles[PITCH];
			ang[YAW] -= nex.cg_refdefViewAngles[YAW];
			if (ang[PITCH] < 0.0)
				ang[PITCH] *= -1.0;
			if (ang[YAW] < 0.0)
				ang[YAW] *= -1.0;
			if (ang[PITCH] > 360.0f)
				ang[PITCH] -= 360.0f;
			if (ang[YAW] > 360.0f)
				ang[YAW] -= 360.0f;
			float aimFov[2];
		aimFov[0] = (ang[PITCH] - 360.0) * -1.0;
			aimFov[1] = (ang[YAW] - 360.0) * -1.0;
			if (ang[PITCH] > aimFov[0])
				ang[PITCH] = aimFov[0];
			if (ang[YAW] > aimFov[1])
				ang[YAW] = aimFov[1];
			if ((ang[PITCH] > aimfov) || (ang[YAW] > aimfov))
				continue;
		}
		if ((entity->distance != 0)
				&& (nearest == -1 || (entity->distance < nex.entities[nearest].distance))) {
			nearest = entityNum;
		}
	}
	return nearest;
}
void CnexAimbot::doAimbot() {
	bool autoShootWeapon = false;
	int targetFlag[2] = { -1, -1 };
	if (BG_PlayerMounted(nex.cg_snap->ps.eFlags) || (nex.cg_snap->ps.weapon == WP_MOBILE_MG42) || (nex.cg_snap->ps.weapon == WP_MOBILE_MG42_SET)) {
		autoShootWeapon = true;
		targetFlag[0] = TARGET_PLAYER_ENEMY | TARGET_PLAYER_BODY;
			if (!bot_aimdead.integer)
				targetFlag[0] |= TARGET_PLAYER_ALIVE;
		targetFlag[1] = targetFlag[0] | TARGET_PLAYER_HEAD;
	} else {
		switch (nex.cg_snap->ps.weapon) {
			case WP_LUGER:
			case WP_SILENCER:
			case WP_AKIMBO_LUGER:
			case WP_AKIMBO_SILENCEDLUGER:
			case WP_COLT:
			case WP_SILENCED_COLT:
			case WP_AKIMBO_COLT:
			case WP_AKIMBO_SILENCEDCOLT:
			case WP_MP40:
			case WP_THOMPSON:
			case WP_GARAND:
			case WP_K43:
			case WP_FG42:
			case WP_STEN:
			case WP_CARBINE:
			case WP_KAR98:
				autoShootWeapon = true;
				targetFlag[0] = TARGET_PLAYER_ENEMY;
					if (!bot_aimdead.integer)
				targetFlag[0] |= TARGET_PLAYER_ALIVE;
					if (bot_headaim.value == 1) {
						targetFlag[0] |= TARGET_PLAYER_HEAD_BODY;
					} else if (bot_headaim.value == 2) {
						targetFlag[0] |= TARGET_PLAYER_HEAD;
					} else if (bot_headaim.value == 3) {
						targetFlag[1] = targetFlag[0] | TARGET_PLAYER_BODY;
						targetFlag[0] |= TARGET_PLAYER_HEAD;
					} else if (bot_headaim.value == 4) {
						targetFlag[0] |= TARGET_PLAYER_BODY;
					}
					break;
				break;
			case WP_GPG40:
			case WP_M7:
				autoShootWeapon = true;
				targetFlag[0] = TARGET_PLAYER_ENEMY | TARGET_PLAYER_ALIVE | TARGET_PLAYER_BODY;
				break;
			case WP_GARAND_SCOPE:
			case WP_K43_SCOPE:
			case WP_FG42SCOPE:
				autoShootWeapon = true;
				targetFlag[0] = TARGET_PLAYER_ENEMY | TARGET_PLAYER_ALIVE | TARGET_PLAYER_HEAD;
				break;
			case WP_KNIFE:
				targetFlag[0] = TARGET_PLAYER_ENEMY | TARGET_PLAYER_ALIVE | TARGET_PLAYER_HEAD;
				targetFlag[1] = TARGET_PLAYER_ENEMY | TARGET_PLAYER_DEAD | TARGET_PLAYER_HEAD;
				break;
			default:
				break;
		}
	}
	targetFlag[0] |= TARGET_PLAYER_ALIVE;
	if ((bot_auto.integer||GetAsyncKeyState(VK_RBUTTON))
			&& (targetFlag[0] != -1) && (nex.cg_snap->ps.clientNum == nex.cg_clientNum)) {
		int count = 0;
		int target;
		for (; count < (sizeof(targetFlag) / sizeof(int)); count++) {
			if (targetFlag[count] != -1) {
				vec3_t aimPoint;
				VectorCopy(vec3_origin, aimPoint);
				target = findNearestTarget(targetFlag[count]);
				if (target == -1)
					continue;
					if( bot_entcam.value == 3 )
					nex.entCamTarget = target;
				
				// Target found
				if (targetFlag[count] & TARGET_PLAYER) {
					if (targetFlag[count] & TARGET_PLAYER_HEAD) {
						VectorCopy(nex.entities[target].head, aimPoint);
					} else if (targetFlag[count] & TARGET_PLAYER_BODY) {
						VectorCopy(nex.entities[target].bodyPart, aimPoint);
					} else if (targetFlag[count] & TARGET_PLAYER_HEAD_BODY) {
						// Head or body ?
						if (nex.entities[target].isHeadVisible)
							VectorCopy(nex.entities[target].head, aimPoint);
						else
							VectorCopy(nex.entities[target].bodyPart, aimPoint);
					} else {

					}
				} else if (targetFlag[count] & TARGET_MISSILE) {
					VectorCopy(nex.entities[target].origin, aimPoint);
				} else {
				}
				
				// If aim point is set, aim and shoot
				if (!VectorCompare(aimPoint, vec3_origin)) {
					if (!bot_human.integer)
					    doAutoShoot(true);
						aimAt(aimPoint);
					blockMouse(true);

					return;
				}
			}
		}
	blockMouse(false);
	}
	doAutoShoot(nexSyscall.isKeyActionDown("+attack"));
}
void CnexAimbot::doVecZ(int player) {
	nexEntity_t *entity = &nex.entities[player];
	if (!IS_PLAYER_ENEMY(player))
		return;
	switch (nex.cg_snap->ps.weapon) {
		case WP_LUGER:
		case WP_SILENCER:
		case WP_AKIMBO_LUGER:
		case WP_AKIMBO_SILENCEDLUGER:
		case WP_COLT:
		case WP_SILENCED_COLT:
		case WP_AKIMBO_COLT:
		case WP_AKIMBO_SILENCEDCOLT:
		case WP_MP40:
		case WP_THOMPSON:
	 	case WP_MOBILE_MG42:
		case WP_GARAND:
		case WP_K43:
		case WP_FG42:
		case WP_STEN:
		case WP_CARBINE:
		case WP_KAR98:
		case WP_GARAND_SCOPE:
		case WP_K43_SCOPE:
		case WP_FG42SCOPE:
					if (bot_hitbox.integer) {
					vec3_t rmin;
					vec3_t rmax;
					VectorCopy(entity->rmin,rmin);
					VectorCopy(entity->rmax,rmax);
					entity->head[0]=entity->head[0]+(rmin[0]+rmax[0])*0.5f;
					entity->head[1]=entity->head[1]+(rmin[1]+rmax[1])*0.5f;
					entity->head[2]=entity->head[2]+(rmin[2]+rmax[2])*0.5f;}
			if (bot_vecauto.integer) {
				#define NEAR_TARGET_VECZ 5.6f
				if (nex.cg_snap->ps.weapon == WP_GARAND_SCOPE || nex.cg_snap->ps.weapon == WP_K43_SCOPE || nex.cg_snap->ps.weapon == WP_FG42SCOPE) {
					VectorMA(entity->head, NEAR_TARGET_VECZ, entity->headAxis[2], entity->head);
					break;
				}
				int nearTarget;
				if (nex.cg_snap->ps.weapon == WP_STEN)
					nearTarget = 700.0f;
				else
					nearTarget = 500.0f;
				if (entity->distance <= nearTarget)
					VectorMA(entity->head, NEAR_TARGET_VECZ, entity->headAxis[2], entity->head);
				else if ((entity->distance > nearTarget) && (entity->distance < 2000.0f))
					VectorMA(entity->head, (NEAR_TARGET_VECZ * (100.0f - ((entity->distance - nearTarget) / 15.0f))) / 100.0f, entity->headAxis[2], entity->head);
			} else {
					switch (nex.cg_snap->ps.weapon) {
						case WP_STEN:
							VectorMA(entity->head, bot_vecz.value, entity->headAxis[2], entity->head);
							break;
						case WP_K43_SCOPE:
						case WP_GARAND_SCOPE:
						case WP_FG42SCOPE:
							VectorMA(entity->head, bot_scopedvecz.value, entity->headAxis[2], entity->head);
							break;
						default:
							VectorMA(entity->head, bot_vecz.value, entity->headAxis[2], entity->head);
							break;
					}
			}
			break;
		default:
			break;
	}
}
void CnexAimbot::doPrediction(int player) {
		snapPredict_t history[MAX_CLIENTS][3];
	if (!bot_enemyprediction.integer)		return;
	
	nexEntity_t *entity = &nex.entities[player];
	if (bot_enemyprediction.value == 1) {
		VectorMA(entity->origin, (float)(nex.cg_frametime) / 1000.0f, nex.cg_entities[player].currentState->pos.trDelta, entity->origin);
		VectorMA (entity->head, nex.cg_snap->ping / 800, nex.cg_entities[player].currentState->pos.trDelta, entity->head);
	} else if (bot_enemyprediction.value == 2) {
		vec3_t velocity;
		VectorScale(nex.cg_entities[player].currentState->pos.trDelta, 1000.0f / ((float)(nex.cg_frametime) - nex.cg_entities[player].currentState->pos.trTime) , velocity);
		VectorMA(entity->origin, (float)(nex.cg_frametime) / 1000.0f, velocity, entity->origin);
		VectorMA(entity->head, (float)(nex.cg_frametime) / 1000.0f, velocity, entity->head);
	} else if (bot_enemyprediction.value == 4) {
	    VectorMA(entity->origin,  (nex.myping/2) * 0.001f, nex.cg_entities[player].currentState->pos.trDelta, entity->origin);
		VectorMA(entity->head, (nex.myping/2)  * 0.001f, nex.cg_entities[player].currentState->pos.trDelta, entity->head);
	} else if (bot_enemyprediction.value == 5 ) {
		snapshotPredict(player);
		VectorMA(entity->origin,  (nex.myping/2) * 0.001f, history[player][0].prPos, entity->origin);
		VectorMA(entity->head, (nex.myping/2)  * 0.001f, history[player][0].prPos, entity->head);
	} 
}
qboolean isAimbotWeapon(int weapon){
	switch( weapon ){
		case WP_LUGER:
		case WP_MP40:
		case WP_GRENADE_LAUNCHER:
		case WP_PANZERFAUST:
		case WP_COLT:
		case WP_THOMPSON:
		case WP_GRENADE_PINEAPPLE:
		case WP_STEN:
		case WP_SILENCER:
		case WP_KAR98:
		case WP_CARBINE:
		case WP_GARAND:
		case WP_MOBILE_MG42:
		case WP_K43:
		case WP_FG42:
		case WP_DUMMY_MG42:
		case WP_AKIMBO_COLT:
		case WP_AKIMBO_LUGER:
		case WP_SILENCED_COLT:
		case WP_GARAND_SCOPE:
		case WP_K43_SCOPE:
		case WP_FG42SCOPE:
		case WP_AKIMBO_SILENCEDCOLT:
		case WP_AKIMBO_SILENCEDLUGER:
		case WP_MOBILE_MG42_SET:
			return qtrue;
		default:
			return qfalse;
	}
	return qfalse;
}