ekknod / EC

open-source cheat [CS:GO/CS2/Apex]
346 stars 161 forks source link

Feature Suggestion: Sonar #116

Open DefaultO opened 2 weeks ago

DefaultO commented 2 weeks ago

Cool project @ekknod. Here's a proof of concept of this for your project. It's not perfect. The beep length calculation is wrong. And there is no pause between the beeps.

I think I will continue to work on this. Planning to add cross-platform compatibility using SDL which allows me to use custom sounds as well. Because I rememebered while trying to find my beep sound, that it wasn't the system beep one.

static void cs2::features::get_closest_target(BOOL ffa, QWORD local_controller, QWORD local_player, QWORD* target, float* distance)
{
    float smallest_distance = NULL;
    QWORD temp_target = NULL;

    for (int i = 1; i < 32; i++)
    {
        QWORD ent = cs2::entity::get_client_entity(i);
        if (ent == 0 || (ent == local_controller)) continue;
        if (!cs2::entity::is_player(ent)) continue;
        QWORD player = cs2::entity::get_player(ent);
        if (player == 0) continue;
        if (ffa == 0 && cs2::player::get_team_num(player) == cs2::player::get_team_num(local_player)) continue;

        vec3 local_origin = cs2::player::get_origin(local_player);
        vec3 origin = cs2::player::get_origin(player);

        float distance = std::sqrt(SQUARE(origin.x - local_origin.x) + SQUARE(origin.y - local_origin.y) + SQUARE(origin.z - local_origin.z));
        if (smallest_distance == NULL || distance < smallest_distance)
        {
            smallest_distance = distance;
            temp_target = player;
        }
    }

    if (temp_target != NULL && smallest_distance > 0)
    {
        *target = temp_target;
        *distance = smallest_distance;
    }
}
update_settings();

// LOG("Sonar enabled: %s\n", config::sonar_enabled ? "true" : "false");

QWORD local_player_controller = cs2::entity::get_local_player_controller();
if (local_player_controller == 0) return;

QWORD local_player = cs2::entity::get_player(local_player_controller);
if (local_player == 0) return;

BOOL  ffa = cs2::gamemode::is_ffa();
QWORD closest_target = NULL;
float distance = NULL;

if (config::sonar_enabled && cs2::player::get_health(local_player) > 0)
{
    get_closest_target(ffa, local_player_controller, local_player, &closest_target, &distance);
    // LOG("Sonar Enabled: Closest Distance: %.2f\n", distance);
    if (distance > 1500 || distance <= 0) return;

    int min_duration = 100;
    int max_duration = 300;
    int interval = static_cast<int>(max_duration - (max_duration - min_duration) * ((1500 - distance) / (1500 - 1)));

    Beep(150, interval);
}

return;
ShirokoLEET commented 2 weeks ago

anyway to add pauses between beeps?

DefaultO commented 2 weeks ago

anyway to add pauses between beeps?

That's what I am trying to use the SDL library for in the future. It can play back audio. Here is some example code: https://gist.github.com/armornick/3447121. Most important thing to me was to be able to playback custom sounds. Which let me find SDL. Then I saw that it also allows for pauses between sounds. Which makes it the perfect library for my use case.

But I personally think that this project needs to be reconstructed. Because you can't have the aimbot running on the same thread as everything else. At least not in the way it is coded in here.

I personally don't use the aimbot, nor do I have an extra fuser at hand for at home to use the ESP features. Which is why I commented everything else out for now. This isn't a solution.