like amiri in my mind
Пользователь
-
Автор темы
- #1
Сделал так, чтобы было понятно новичкам, но также по моему мнению его можно взять и за основу, постепенно улучшая, значений из конфигов добавлять не стал, можете сразу вставить в базу и поиграть с ним.
cpp:
#include "ragebot.h"
// used: cheat variables
#include "../core/variables.h"
//used : cliententity list
#include "../core/interfaces.h"
// used: global variables
#include "../global.h"
//used: autowall
#include "autowall.h"
//used: CalcAngle
#include "../utilities/math.h"
void CRageBot::Run(CUserCmd* pCmd, CBaseEntity* pLocal, bool& bSendPacket)
{
//init local player
LocalPlayer = pLocal;
//check sanity
if (!LocalPlayer->IsAlive())
return;
/* get valid entities, target sort, get best point, hitscan and aim (hf c:) */
// FYI - https://www.unknowncheats.me/forum/counterstrike-global-offensive/345397-performance-raytracer.html
//reset data to get valid data each tick
ResetData();
//get all available targets on server (sanity check)
GetTargetsArray();
if (TargetsArray.empty())
return;
FindOptimalTarget();
if (!FinalTarget)
return;
Aim(FinalPoint, pCmd);
}
void CRageBot::ResetData() {
TargetsArray.clear(); // clear all available targets on server
FinalTarget = nullptr; // final target that we will shoot at
FinalPoint = Vector(); // point we will chose on final target
}
bool CRageBot::ValidatePlayer(CBaseEntity* pPlayer, bool CheckDormacy) {
//get anomaly entities outta here
if (pPlayer == nullptr || !pPlayer->IsPlayer())
return false;
if (!pPlayer->IsAlive() || pPlayer->GetTeam() == LocalPlayer->GetTeam())
return false;
if (!CheckDormacy && pPlayer->IsDormant())
return false;
return true;
}
void CRageBot::GetTargetsArray() {
for (int EntIndex = 1; EntIndex < I::Globals->nMaxClients; EntIndex++)
{
CBaseEntity* pEntity = I::ClientEntityList->Get<CBaseEntity>(EntIndex);
//add entity to TargetArray if it is valid
if (ValidatePlayer(pEntity, true))
TargetsArray.emplace_back(pEntity);
}
}
void CRageBot::FindOptimalTarget() {
//iterate available targets from TargetsArray
for (auto& Target : TargetsArray)
{
auto CurrPoints = GetPlayerPoints(Target);
auto BestPoint = GetBestPoint(CurrPoints);
if (BestPoint == Vector())
continue;
FinalTarget = Target;
FinalPoint = BestPoint;
}
return;
}
std::vector <Vector> CRageBot::GetPlayerPoints(CBaseEntity* pPlayer) {
std::vector <Vector> Points;
//start iterate from 0 ( HITBOX_HEAD )
for (auto HboxIndex = 0; HboxIndex <= sizeof(EHitboxIndex); HboxIndex++) {
Points.emplace_back(pPlayer->GetHitboxPosition(HboxIndex).value());
}
return Points;
}
Vector CRageBot::GetBestPoint(std::vector <Vector> Points) {
auto NeededDmg = 25;
//start iterate available Points
for (auto& Point : Points) {
if (CAutoWall::GetDamage(LocalPlayer, Point) >= NeededDmg)
return Point;
}
return Vector();
}
void CRageBot::Aim(Vector AimPoint, CUserCmd* pCmd) {
auto Angle = M::CalcAngle(LocalPlayer->GetEyePosition(), AimPoint);
//if we have not achieved accuracy we skip this tick and stop local player
if (!AchievedAccuracy()) {
StopLocalPlayer(pCmd);
return;
}
pCmd->angViewPoint = Angle; // aim at point we have chosen
pCmd->iButtons |= IN_ATTACK; // shot at player
}
//Do your accuracy related things
bool CRageBot::AchievedAccuracy() {
//tip : here u already can manipulate with FinalTarget and his matrix to implement hitchance
auto CurrWeap = LocalPlayer->GetWeapon();
float Inaccuracy = CurrWeap->GetInaccuracy();
if (Inaccuracy <= 0.01)
return true;
return false;
}
void CRageBot::StopLocalPlayer(CUserCmd* pCmd) {
//fix bounds
if (LocalPlayer->GetVelocity().Length2D() <= 30.f)
return;
QAngle Direction;
QAngle RealView;
Vector Velocity = LocalPlayer->GetVelocity();
float Speed = Velocity.Length2D();
M::VectorAngles(Velocity, Direction);
I::Engine->GetViewAngles(RealView);
Direction.y = RealView.y - Direction.y;
Vector Forward;
M::AngleVectors(Direction, &Forward);
pCmd->flSideMove = Forward.y * -Speed;
pCmd->flForwardMove = Forward.x * -Speed;
}
hpp:
#pragma once
// used: winapi includes, singleton
#include "../common.h"
// used: usercmd
#include "../sdk/datatypes/usercmd.h"
// used: angle
#include "../sdk/datatypes/qangle.h"
// used: baseentity
#include "../sdk/entity.h"
// FYI - https://www.unknowncheats.me/forum/general-programming-and-reversing/173986-math-hack-2-predicting-future-3d-kinematics.html
class CRageBot : public CSingleton<CRageBot>
{
public:
// Get
void Run(CUserCmd* pCmd, CBaseEntity* pLocal, bool& bSendPacket);
// Global Values
CBaseEntity* pBestEntity = nullptr;
private:
// Main
void ResetData();
/* get entities, choose best target, aim */
void GetTargetsArray();
void FindOptimalTarget();
void Aim(Vector AimPoint, CUserCmd* pCmd);
// Other
/* 3-rd party functions */
//get points to aim at
std::vector <Vector> GetPlayerPoints(CBaseEntity* pPlayer);
Vector GetBestPoint(std::vector <Vector> Points);
//achieving needed accuracy
bool AchievedAccuracy();
void StopLocalPlayer(CUserCmd* pCmd);
// Check
/* is entity valid */
bool ValidatePlayer(CBaseEntity* pPlayer, bool CheckDormacy);
// Values
/* hitbox position other info */
//all available target at this tick
std::vector <CBaseEntity*> TargetsArray;
//final target related info
CBaseEntity* FinalTarget;
Vector FinalPoint;
CBaseEntity* LocalPlayer;
};
Последнее редактирование: