Skip to content

Commit

Permalink
Merge pull request #103 from gingerchicken/master
Browse files Browse the repository at this point in the history
Add simple aimbot
  • Loading branch information
maecry authored Jul 29, 2024
2 parents 5e1cc42 + b50a0db commit a3f79df
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 2 deletions.
24 changes: 23 additions & 1 deletion cstrike/core/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,29 @@ void T::RageBot()
{ }

void T::LegitBot()
{ }
{
ImGui::BeginChild(CS_XOR("legitbot.aimbot"), ImVec2{}, true, ImGuiWindowFlags_MenuBar);
{
if (ImGui::BeginMenuBar())
{
ImGui::TextUnformatted(CS_XOR("aimbot"));
ImGui::EndMenuBar();
}

ImGui::Checkbox(CS_XOR("enable##aimbot"), &C_GET(bool, Vars.bLegitbot));
ImGui::SliderFloat(CS_XOR("smoothing"), &C_GET(float, Vars.flSmoothing), 1.f, 100.f);

ImGui::NewLine();
// Key
ImGui::Checkbox(CS_XOR("always on##aimbot"), &C_GET(bool, Vars.bLegitbotAlwaysOn));
ImGui::BeginDisabled(C_GET(bool, Vars.bLegitbotAlwaysOn));
{
ImGui::HotKey(CS_XOR("toggle key"), &C_GET(unsigned int, Vars.nLegitbotActivationKey));
}
ImGui::EndDisabled();
}
ImGui::EndChild();
}

void T::Visuals()
{
Expand Down
6 changes: 6 additions & 0 deletions cstrike/core/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ struct Variables_t
C_ADD_VARIABLE(ColorPickerVar_t, colAccent1, ColorPickerVar_t(100, 105, 175)); // (dark)
C_ADD_VARIABLE(ColorPickerVar_t, colAccent2, ColorPickerVar_t(115, 120, 190)); // (darker)
#pragma endregion
#pragma region variables_legitbot
C_ADD_VARIABLE(bool, bLegitbot, false);
C_ADD_VARIABLE(float, flSmoothing, 10.0f);
C_ADD_VARIABLE(bool, bLegitbotAlwaysOn, false);
C_ADD_VARIABLE(unsigned int, nLegitbotActivationKey, VK_HOME);
#pragma endregion
};

inline Variables_t Vars = {};
4 changes: 4 additions & 0 deletions cstrike/cstrike.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
<ClInclude Include="core\variables.h" />
<ClInclude Include="features.h" />
<ClInclude Include="features\CRC.h" />
<ClInclude Include="features\legitbot\aim.h" />
<ClInclude Include="features\legitbot\legitbot.h" />
<ClInclude Include="features\misc.h" />
<ClInclude Include="features\misc\movement.h" />
<ClInclude Include="features\visuals.h" />
Expand Down Expand Up @@ -227,6 +229,8 @@
<ClCompile Include="..\dependencies\minhook\hde\hde64.c" />
<ClCompile Include="..\dependencies\minhook\hook.c" />
<ClCompile Include="..\dependencies\minhook\trampoline.c" />
<ClCompile Include="features\legitbot.cpp" />
<ClCompile Include="features\legitbot\aim.cpp" />
<ClCompile Include="sdk\interfaces\cgametracemanager.cpp" />
<ClCompile Include="core.cpp" />
<ClCompile Include="core\config.cpp" />
Expand Down
15 changes: 15 additions & 0 deletions cstrike/cstrike.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<Filter Include="utilities">
<UniqueIdentifier>{212A0ED3-8D94-C249-D6D2-73EF427CA09E}</UniqueIdentifier>
</Filter>
<Filter Include="features\legitbot">
<UniqueIdentifier>{a0df371b-f244-4c53-b08d-762a0f9b6b0c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\dependencies\imgui\imconfig.h">
Expand Down Expand Up @@ -314,6 +317,12 @@
<ClInclude Include="sdk\interfaces\cgametracemanager.h">
<Filter>sdk\interfaces</Filter>
</ClInclude>
<ClInclude Include="features\legitbot\legitbot.h">
<Filter>features</Filter>
</ClInclude>
<ClInclude Include="features\legitbot\aim.h">
<Filter>features\legitbot</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\dependencies\imgui\imgui.cpp">
Expand Down Expand Up @@ -427,5 +436,11 @@
<ClCompile Include="sdk\interfaces\cgametracemanager.cpp">
<Filter>sdk\interfaces</Filter>
</ClCompile>
<ClCompile Include="features\legitbot\aim.cpp">
<Filter>features\legitbot</Filter>
</ClCompile>
<ClCompile Include="features\legitbot.cpp">
<Filter>features</Filter>
</ClCompile>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions cstrike/features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// used: features callbacks
#include "features/visuals.h"
#include "features/misc.h"
#include "features/legitbot.h"

// used: interfaces
#include "core/interfaces.h"
Expand Down Expand Up @@ -70,6 +71,7 @@ void F::OnCreateMove(CUserCmd* pCmd, CBaseUserCmdPB* pBaseCmd, CCSPlayerControll
return;

F::MISC::OnMove(pCmd, pBaseCmd, pLocalController, pLocalPawn);
F::LEGITBOT::OnMove(pCmd, pBaseCmd, pLocalController, pLocalPawn);
}

bool F::OnDrawObject(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2)
Expand Down
9 changes: 9 additions & 0 deletions cstrike/features/legitbot.cpp
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);
}
10 changes: 10 additions & 0 deletions cstrike/features/legitbot.h
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);
}
158 changes: 158 additions & 0 deletions cstrike/features/legitbot/aim.cpp
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();
}
17 changes: 17 additions & 0 deletions cstrike/features/legitbot/aim.h
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);
}
10 changes: 10 additions & 0 deletions cstrike/features/legitbot/legitbot.h
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);
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

[] CHAMS - basic chams system

[x] AIMBOT - none...
[] AIMBOT - simple head aimbot with smoothing

## License

Expand Down

0 comments on commit a3f79df

Please sign in to comment.