-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from gingerchicken/master
Add simple aimbot
- Loading branch information
Showing
11 changed files
with
255 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "legitbot.h" | ||
|
||
// used: movement callback | ||
#include "legitbot/aim.h" | ||
|
||
void F::LEGITBOT::OnMove(CUserCmd* pCmd, CBaseUserCmdPB* pBaseCmd, CCSPlayerController* pLocalController, C_CSPlayerPawn* pLocalPawn) | ||
{ | ||
AIM::OnMove(pCmd, pBaseCmd, pLocalController, pLocalPawn); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
class CUserCmd; | ||
class CBaseUserCmdPB; | ||
class CCSPlayerController; | ||
class C_CSPlayerPawn; | ||
|
||
namespace F::LEGITBOT | ||
{ | ||
void OnMove(CUserCmd* pCmd, CBaseUserCmdPB* pBaseCmd, CCSPlayerController* pLocalController, C_CSPlayerPawn* pLocalPawn); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
#include "aim.h" | ||
|
||
// used: sdk entity | ||
#include "../../sdk/entity.h" | ||
#include "../../sdk/interfaces/cgameentitysystem.h" | ||
#include "../../sdk/interfaces/iengineclient.h" | ||
// used: cusercmd | ||
#include "../../sdk/datatypes/usercmd.h" | ||
|
||
// used: activation button | ||
#include "../../utilities/inputsystem.h" | ||
|
||
// used: cheat variables | ||
#include "../../core/variables.h" | ||
|
||
void F::LEGITBOT::AIM::OnMove(CUserCmd* pCmd, CBaseUserCmdPB* pBaseCmd, CCSPlayerController* pLocalController, C_CSPlayerPawn* pLocalPawn) | ||
{ | ||
// Check if the legitbot is enabled | ||
if (!C_GET(bool, Vars.bLegitbot)) | ||
return; | ||
|
||
if (!pLocalController->IsPawnAlive()) | ||
return; | ||
|
||
AimAssist(pBaseCmd, pLocalPawn, pLocalController); | ||
} | ||
|
||
QAngle_t GetAngularDifference(CBaseUserCmdPB* pCmd, Vector_t vecTarget, C_CSPlayerPawn* pLocal) | ||
{ | ||
// The current position | ||
Vector_t vecCurrent = pLocal->GetEyePosition(); | ||
|
||
// The new angle | ||
QAngle_t vNewAngle = (vecTarget - vecCurrent).ToAngles(); | ||
vNewAngle.Normalize(); // Normalise it so we don't jitter about | ||
|
||
// Store our current angles | ||
QAngle_t vCurAngle = pCmd->pViewAngles->angValue; | ||
|
||
// Find the difference between the two angles (later useful when adding smoothing) | ||
vNewAngle -= vCurAngle; | ||
|
||
return vNewAngle; | ||
} | ||
|
||
float GetAngularDistance(CBaseUserCmdPB* pCmd, Vector_t vecTarget, C_CSPlayerPawn* pLocal) | ||
{ | ||
return GetAngularDifference(pCmd, vecTarget, pLocal).Length2D(); | ||
} | ||
|
||
void F::LEGITBOT::AIM::AimAssist(CBaseUserCmdPB* pUserCmd, C_CSPlayerPawn* pLocalPawn, CCSPlayerController* pLocalController) | ||
{ | ||
// Check if the activation key is down | ||
if (!IPT::IsKeyDown(C_GET(unsigned int, Vars.nLegitbotActivationKey)) && !C_GET(bool, Vars.bLegitbotAlwaysOn)) | ||
return; | ||
|
||
// The current best distance | ||
float flDistance = INFINITY; | ||
// The target we have chosen | ||
CCSPlayerController* pTarget = nullptr; | ||
// Cache'd position | ||
Vector_t vecBestPosition = Vector_t(); | ||
|
||
// Entity loop | ||
const int iHighestIndex = I::GameResourceService->pGameEntitySystem->GetHighestEntityIndex(); | ||
|
||
for (int nIndex = 1; nIndex <= iHighestIndex; nIndex++) | ||
{ | ||
// Get the entity | ||
C_BaseEntity* pEntity = I::GameResourceService->pGameEntitySystem->Get(nIndex); | ||
if (pEntity == nullptr) | ||
continue; | ||
|
||
// Get the class info | ||
SchemaClassInfoData_t* pClassInfo = nullptr; | ||
pEntity->GetSchemaClassInfo(&pClassInfo); | ||
if (pClassInfo == nullptr) | ||
continue; | ||
|
||
// Get the hashed name | ||
const FNV1A_t uHashedName = FNV1A::Hash(pClassInfo->szName); | ||
|
||
// Make sure they're a player controller | ||
if (uHashedName != FNV1A::HashConst("CCSPlayerController")) | ||
continue; | ||
|
||
// Cast to player controller | ||
CCSPlayerController* pPlayer = reinterpret_cast<CCSPlayerController*>(pEntity); | ||
if (pPlayer == nullptr) | ||
continue; | ||
|
||
// Check the entity is not us | ||
if (pPlayer == pLocalController) | ||
continue; | ||
|
||
// Get the player pawn | ||
C_CSPlayerPawn* pPawn = I::GameResourceService->pGameEntitySystem->Get<C_CSPlayerPawn>(pPlayer->GetPawnHandle()); | ||
if (pPawn == nullptr) | ||
continue; | ||
|
||
// Make sure they're alive | ||
if (!pPlayer->IsPawnAlive()) | ||
continue; | ||
|
||
// Check if they're an enemy | ||
if (!pLocalPawn->IsOtherEnemy(pPawn)) | ||
continue; | ||
|
||
// Check if they're dormant | ||
CGameSceneNode* pCGameSceneNode = pPawn->GetGameSceneNode(); | ||
if (pCGameSceneNode == nullptr || pCGameSceneNode->IsDormant()) | ||
continue; | ||
|
||
// Get the position | ||
|
||
// Firstly, get the skeleton | ||
CSkeletonInstance* pSkeleton = pCGameSceneNode->GetSkeletonInstance(); | ||
if (pSkeleton == nullptr) | ||
continue; | ||
// Now the bones | ||
Matrix2x4_t* pBoneCache = pSkeleton->pBoneCache; | ||
if (pBoneCache == nullptr) | ||
continue; | ||
|
||
const int iBone = 6; // You may wish to change this dynamically but for now let's target the head. | ||
|
||
// Get the bone's position | ||
Vector_t vecPos = pBoneCache->GetOrigin(iBone); | ||
|
||
// Get the distance/weight of the move | ||
float flCurrentDistance = GetAngularDistance(pUserCmd, vecPos, pLocalPawn); | ||
if (pTarget && flCurrentDistance > flDistance) // Override if this is the first move or if it is a better move | ||
continue; | ||
|
||
// Better move found, override. | ||
pTarget = pPlayer; | ||
flDistance = flCurrentDistance; | ||
vecBestPosition = vecPos; | ||
} | ||
|
||
// Check if a target was found | ||
if (pTarget == nullptr) | ||
return; | ||
|
||
// Point at them | ||
QAngle_t* pViewAngles = &(pUserCmd->pViewAngles->angValue); // Just for readability sake! | ||
|
||
// Find the change in angles | ||
QAngle_t vNewAngles = GetAngularDifference(pUserCmd, vecBestPosition, pLocalPawn); | ||
|
||
// Get the smoothing | ||
const float flSmoothing = C_GET(float, Vars.flSmoothing); | ||
|
||
// Apply smoothing and set angles | ||
pViewAngles->x += vNewAngles.x / flSmoothing; | ||
pViewAngles->y += vNewAngles.y / flSmoothing; | ||
pViewAngles->Normalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
class CUserCmd; | ||
class CBaseUserCmdPB; | ||
class CCSGOInputHistoryEntryPB; | ||
|
||
class CCSPlayerController; | ||
class C_CSPlayerPawn; | ||
|
||
struct QAngle_t; | ||
|
||
namespace F::LEGITBOT::AIM | ||
{ | ||
void OnMove(CUserCmd* pCmd, CBaseUserCmdPB* pBaseCmd, CCSPlayerController* pLocalController, C_CSPlayerPawn* pLocalPawn); | ||
|
||
void AimAssist(CBaseUserCmdPB* pUserCmd, C_CSPlayerPawn* pLocalPawn, CCSPlayerController* pLocalController); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
class CUserCmd; | ||
class CBaseUserCmdPB; | ||
class CCSPlayerController; | ||
class C_CSPlayerPawn; | ||
|
||
namespace F::LEGITBOT | ||
{ | ||
void OnMove(CBaseUserCmdPB* pBaseCmd, CCSPlayerController* pLocalController, C_CSPlayerPawn* pLocalPawn); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters