Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "Legit.h"
- VITRUVIA_INIT
- F_Legit* Legit;
- using sorter_function = std::function<bool(const Target_t& a, const Target_t& b)>;
- std::array<sorter_function, 4> sorters
- {
- // Health
- [](const Target_t& a, const Target_t& b) -> bool
- {
- return a.GetHealth() > b.GetHealth();
- },
- // Distance
- [](const Target_t& a, const Target_t& b) -> bool
- {
- return a.GetDistance() > b.GetDistance();
- },
- // FOV
- [](const Target_t& a, const Target_t& b) -> bool
- {
- return a.GetCrosshairDistance() > b.GetCrosshairDistance();
- },
- // Threat
- [](const Target_t& a, const Target_t& b) -> bool
- {
- return a.GetThreat() > b.GetThreat();
- }
- };
- using shooter_function = std::function<bool(const Source::CUserCmd*, int)>;
- std::array<shooter_function, 3> shooters
- {
- // On Fire
- [](const Source::CUserCmd* cmd, int) -> bool
- {
- return cmd->buttons & IN_ATTACK;
- },
- // On Key
- [](const Source::CUserCmd*, int button) -> bool
- {
- return Source::InputSystem->IsButtonDown((Source::ButtonCode_t)button);
- },
- // On Sight
- [](const Source::CUserCmd*, int) -> bool
- {
- return true;
- }
- };
- bool F_Legit::FindTarget()
- {
- using namespace Source;
- // The objective of this function is to fill m_TargetList, sort it, and grab the best target to aim at.
- auto local = C_CSPlayer::GetLocal();
- // If the local player has got an invalid weapon in hands, return prematurely
- if (local->GotInvalidWeapon())
- return false;
- // Used to track down entities I'm pushing in the targets array
- int target_index = 0;
- // Retrieve the config table to use based on the local active weapon if the user wants weapon groups
- Config::cLegit::cAimbot cfg = Config::Aimbot;
- // If the user doesn't want to use weapon groups, the cfg will stay the same
- if (Config::Aimbot.UseGroups.m_Value)
- {
- // If he wants, I edit the cfg using the weapon cfg
- auto cfg_weap = Config::WeaponGroups[local->GetActiveWeapon()->GetWeaponInfo()->iWeaponType];
- cfg.Active = cfg_weap->Active;
- cfg.Hitbox = cfg_weap->Hitbox;
- cfg.FOV = cfg_weap->FOV;
- cfg.Smooth = cfg_weap->Smooth;
- cfg.Time = cfg_weap->Time;
- }
- if (!cfg.Active.m_Value)
- return false;
- // Loop through the clients
- FOR_EACH_CLIENT
- {
- // Grab the entity and perform several validity checks on it
- auto entity = GET_ENTITY(ClientIndex);
- // If the entity is not found skip
- if (entity == nullptr)
- continue;
- // If the entity is the local player, skip
- if (entity == local)
- continue;
- // If the entity is dormant, skip
- if (entity->GetNetworkable()->IsDormant())
- continue;
- // If the entity is dead, skip
- if (entity->m_iHealth() <= 0)
- continue;
- // If the entity has got spawn immunity, skip
- if (entity->m_bGunGameImmunity())
- continue;
- // If config needs to skip team mates
- if (!cfg.TeamMates.m_Value)
- {
- // If the entity is a team mate, skip
- if (entity->m_iTeamNum() == local->m_iTeamNum())
- continue;
- }
- // If config needs to skip targets behind a smoke
- if (cfg.SmokeCheck.m_Value)
- {
- // If the entity is behind a smoke, skip
- if (entity->IsBehindSmoke(cfg.Hitbox.m_Value))
- continue;
- }
- // If config needs to skip targets that aren't visible
- if (cfg.VisibleCheck.m_Value)
- {
- // If entity isn't visible, skip
- if (!entity->IsVisible(cfg.Hitbox.m_Value))
- continue;
- }
- // Get the hitbox position
- Vector hitbox_position = entity->GetHitboxPosition(cfg.Hitbox.m_Value);
- if (hitbox_position == Vector(0, 0, 0)) continue;
- // Check for FOV
- if (cfg.FOV.m_Value > 0.f)
- {
- if (Maths::GetFov(m_pCmd->viewangles, local->GetEyePosition(), hitbox_position) > cfg.FOV.m_Value)
- continue;
- }
- // Calculate the angle I need to aim at if this is the best entity and normalize it
- Vector aim_angle = Maths::GetAngle(local->GetEyePosition(), hitbox_position);
- aim_angle = Maths::NormalizeAngle(aim_angle);
- // Correct the recoil based on RCS amount
- aim_angle -= local->m_aimPunchAngle() * cfg.RCSFactor.m_Value;
- aim_angle = Maths::NormalizeAngle(aim_angle);
- // Add a new target to the list
- m_TargetList[target_index] = Target_t(local, entity, aim_angle, hitbox_position);
- target_index++;
- }
- // If I've actually found entities good enough to aim at, I can start the sorting
- if (target_index > 0)
- {
- // Sort in C++11 style based on the SortBy cfg value
- std::sort(m_TargetList.begin(), m_TargetList.end(), sorters[cfg.SortBy.m_Value]);
- // Now the value at the beginning of the list contains the actual best entity
- m_BestTarget = m_TargetList[0];
- return true;
- }
- return false;
- }
- void F_Legit::AimTarget()
- {
- using namespace Source;
- // If I'm calling this function it means that FindTarget() returned true, which means that m_pBestTarget is not null
- // Now all I need to do is to aim at him, always based on the config
- auto local = C_CSPlayer::GetLocal();
- // Retrieve the config table to use based on the local active weapon if the user wants weapon groups
- Config::cLegit::cAimbot cfg = Config::Aimbot;
- // If the user doesn't want to use weapon groups, the cfg will stay the same
- if (Config::Aimbot.UseGroups.m_Value)
- {
- // If he wants, I edit the cfg using the weapon cfg
- auto cfg_weap = Config::WeaponGroups[local->GetActiveWeapon()->GetWeaponInfo()->iWeaponType];
- cfg.Active = cfg_weap->Active;
- cfg.Hitbox = cfg_weap->Hitbox;
- cfg.FOV = cfg_weap->FOV;
- cfg.Smooth = cfg_weap->Smooth;
- cfg.Time = cfg_weap->Time;
- }
- // Different behaviour based on the value of cfg.Mode
- if (shooters[cfg.Mode.m_Value](m_pCmd, cfg.AimKey.m_Value))
- {
- Vector best_angle = m_BestTarget.GetAimbotAngle();
- // If the user wants to apply smooth
- if (cfg.Smooth.m_Value > 0.f)
- {
- // I smooth
- Maths::SmoothAngles(m_pCmd->viewangles, best_angle, cfg.Smooth.m_Value);
- }
- // Normalize the angle
- best_angle = Maths::NormalizeAngle(best_angle);
- // Apply the angles
- (cfg.Silent.m_Value) ?
- m_pCmd->viewangles = best_angle :
- Source::Engine->SetViewAngles(best_angle);
- }
- }
- void F_Legit::OnCreateMove(Source::CUserCmd* pCmd)
- {
- // Set the cmd pointer to work on
- this->m_pCmd = pCmd;
- // Reset best target
- this->m_BestTarget.Reset();
- // Reset target list
- std::fill(m_TargetList.begin(), m_TargetList.end(), Target_t());
- // Let's find the target
- if (this->FindTarget())
- {
- // If target is found, aim at it
- this->AimTarget();
- }
- }
- VITRUVIA_END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement