Optimized Aimbot code. (#2653)

* Fixed hypot call not considering the Z coordinates.
Refactored class-based variables.
Fixed on_player/on_enemy/on_police/on_npc config variables not being persisted to disk.
This commit is contained in:
gir489 2024-01-27 05:51:23 -05:00 committed by GitHub
parent dd27ea2340
commit deac08e856
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 26 deletions

View File

@ -5,20 +5,20 @@
#include <numbers>
namespace big
{
inline Vector3 aim_lock;
inline Vector3 smooth_factor;
inline bool using_aimbot_first_time = true;
inline Entity target_entity;
class aimbot : looped_command
{
static inline Vector3 aim_lock;
static inline Vector3 smooth_factor;
static inline bool initalized;
static inline Entity target_entity;
using looped_command::looped_command;
virtual void on_tick() override
{
float local_fov_change = g.weapons.aimbot.fov;
for (auto ped : entity::get_entities(false, true))
{
if (!ENTITY::IS_ENTITY_DEAD(ped, 0)) // Tracetype is always 17. LOS check
if (!ENTITY::IS_ENTITY_DEAD(ped, 0))
{
int relation = PED::GET_RELATIONSHIP_BETWEEN_PEDS(ped, self::ped); // relation for enemy check
int type = PED::GET_PED_TYPE(ped); // for police check, cop types are 6, swat is 27
@ -52,13 +52,12 @@ namespace big
// Update aim lock coords
aimbot_handler:
{
if (!ENTITY::HAS_ENTITY_CLEAR_LOS_TO_ENTITY(self::ped, ped, 17))
if (!ENTITY::HAS_ENTITY_CLEAR_LOS_TO_ENTITY_ADJUST_FOR_COVER(self::ped, ped, 17))
continue;
// Jump to here to handle instead of continue statements
target_entity = ped;
aim_lock =
ENTITY::GET_WORLD_POSITION_OF_ENTITY_BONE(ped, PED::GET_PED_BONE_INDEX(ped, g.weapons.aimbot.selected_bone));
aim_lock = ENTITY::GET_ENTITY_BONE_POSTION(ped, PED::GET_PED_BONE_INDEX(ped, g.weapons.aimbot.selected_bone));
}
}
}
@ -66,14 +65,14 @@ namespace big
{
return;
}
if (PED::GET_PED_CONFIG_FLAG(self::ped, 78, 0))
if (PLAYER::IS_PLAYER_FREE_AIMING(self::id))
{
Vector3 camera_target;
if (g.weapons.aimbot.smoothing)
{
//Avoid buggy cam
if (using_aimbot_first_time)
if (!initalized)
{
Vector3 cam_coords = CAM::GET_GAMEPLAY_CAM_COORD();
Vector3 cam_rot = CAM::GET_GAMEPLAY_CAM_ROT(0);
@ -82,8 +81,8 @@ namespace big
Vector3 multiply = cam_direction * distance;
Vector3 front_cam = cam_coords + multiply;
camera_target = front_cam - CAM::GET_GAMEPLAY_CAM_COORD();
smooth_factor = camera_target;
using_aimbot_first_time = false;
smooth_factor = camera_target;
initalized = true;
}
Vector3 target = aim_lock - CAM::GET_GAMEPLAY_CAM_COORD();
smooth_factor.x += (target.x - smooth_factor.x) * g.weapons.aimbot.smoothing_speed / 10.f;
@ -101,10 +100,9 @@ namespace big
if (aim_lock.x == 0.f && aim_lock.y == 0.f && aim_lock.z == 0.f)
return;
float RADPI = 180.0f / std::numbers::pi;
float camera_heading = atan2f(camera_target.x, camera_target.y) * RADPI;
float magnitude = sqrtf(camera_target.x * camera_target.x + camera_target.y * camera_target.y
+ camera_target.z * camera_target.z);
constexpr float RADPI = 180.0f / std::numbers::pi;
float magnitude = std::hypot(camera_target.x, camera_target.y, camera_target.z);
float camera_heading = atan2f(camera_target.x, camera_target.y) * RADPI;
float camera_pitch = asinf(camera_target.z / magnitude) * RADPI;
float self_heading = ENTITY::GET_ENTITY_HEADING(self::ped);
@ -131,12 +129,12 @@ namespace big
else
{
target_entity = 0;
using_aimbot_first_time = true;
initalized = false;
}
}
virtual void on_disable() override
{
using_aimbot_first_time = true;
initalized = false;
}
};

View File

@ -853,7 +853,7 @@ namespace big
float fov = 90.f;
float distance = 200.f;
uint32_t selected_bone = 0x796E; // Default to head
NLOHMANN_DEFINE_TYPE_INTRUSIVE(aimbot, enable, smoothing, smoothing_speed, fov, distance, selected_bone)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(aimbot, enable, smoothing, smoothing_speed, on_player, on_enemy, on_police, on_npc, fov, distance)
} aimbot{};
struct flying_axe

View File

@ -50,7 +50,7 @@ namespace big
command_arguments _args(args);
command->call(_args);
}
if (ImGui::IsItemHovered())
if (ImGui::IsItemHovered() && !command->get_description().empty())
ImGui::SetTooltip(command->get_description().c_str());
}
@ -63,7 +63,7 @@ namespace big
if (ImGui::Button(label_override.value_or(command->get_label()).data()))
command->call(player, args);
if (ImGui::IsItemHovered())
if (ImGui::IsItemHovered() && !command->get_description().empty())
ImGui::SetTooltip(command->get_description().c_str());
}
@ -80,7 +80,7 @@ namespace big
bool updated;
if (updated = ImGui::Checkbox(label_override.value_or(command->get_label()).data(), &command->is_enabled()))
command->refresh();
if (ImGui::IsItemHovered())
if (ImGui::IsItemHovered() && !command->get_description().empty())
ImGui::SetTooltip(command->get_description().c_str());
return updated;
@ -98,7 +98,7 @@ namespace big
command->get_lower_bound(),
command->get_upper_bound());
if (ImGui::IsItemHovered())
if (ImGui::IsItemHovered() && !command->get_description().empty())
ImGui::SetTooltip(command->get_description().c_str());
}
@ -114,7 +114,7 @@ namespace big
command->get_lower_bound(),
command->get_upper_bound());
if (ImGui::IsItemHovered())
if (ImGui::IsItemHovered() && !command->get_description().empty())
ImGui::SetTooltip(command->get_description().c_str());
}
@ -130,7 +130,7 @@ namespace big
command->get_lower_bound(),
command->get_upper_bound());
if (ImGui::IsItemHovered())
if (ImGui::IsItemHovered() && !command->get_description().empty())
ImGui::SetTooltip(command->get_description().c_str());
}