What's new

Welcome to HvH Forum!

SignUp Now! Download Free HvH CS2/CS:GO Cheats, CFG, LUA/JS Scripts, And More!


SignUp Now!

Source Code A method based on geometry to calc hitchance

Newbie HvHer
User ID
103729
Messages
2
Reactions
2
Level
4
No comments in code, don't ask why
Directly paste it into airflow source code

C++:
bool hitchance(vec3_t eye_pos, rage_player_t& rage, const rage_point_t& point, anim_record_t* record, const float& chance, matrix3x4_t* matrix, float* hitchance_out = nullptr)
{
    static auto weapon_accuracy_nospread = HACKS->convars.weapon_accuracy_nospread;

    if (weapon_accuracy_nospread && weapon_accuracy_nospread->get_bool())
    {
        if (hitchance_out) *hitchance_out = 1.f;
        return true;
    }

    auto net_vars = ENGINE_PREDICTION->get_networked_vars(HACKS->cmd->command_number);
    float inaccuracy = net_vars->inaccuracy + net_vars->spread;

    if ((HACKS->ideal_inaccuracy + 0.0005f) >= net_vars->inaccuracy)
    {
        if (hitchance_out) *hitchance_out = 1.f;
        return true;
    }

    auto matrix_to_aim = record->extrapolated ? record->predicted_matrix : record->matrix_orig.matrix;
    auto active_matrix = matrix ? matrix : matrix_to_aim;

    rage.restore.store(rage.player);
    LAGCOMP->set_record(rage.player, record, active_matrix);

    vec3_t aim_dir = (point.aim_point - eye_pos).normalized();
    float dist = eye_pos.dist_to(point.aim_point);
    float spread_r = dist * inaccuracy;

    float tgt_r = 0.f;
    vec3_t tgt_center{};

    if (auto hdr = HACKS->model_info->get_studio_model(rage.player->get_model()))
    {
        if (auto set = hdr->hitbox_set(0))
        {
            if (auto box = set->hitbox(point.hitbox))
            {
                vec3_t mn, mx;
                math::vector_transform(box->min, active_matrix[box->bone], mn);
                math::vector_transform(box->max, active_matrix[box->bone], mx);
                tgt_center = (mn + mx) * 0.5f;
                tgt_r = box->radius > 0.f ? box->radius : (mx - mn).length() * 0.5f;
            }
        }
    }

    vec3_t diff = tgt_center - point.aim_point;
    float d = (diff - aim_dir * diff.dot(aim_dir)).length();

    // Geometric analysis
    auto overlap_ratio = [&](float r1, float r2, float sep) -> float
        {
            if (r1 <= 0.f)
                return 0.f;

            if (sep >= r1 + r2)
                return 0.f;

            if (sep <= std::fabs(r1 - r2))
                return r2 <= r1 ? (r2 * r2) / (r1 * r1) : 1.f;

            float r1sq = r1 * r1, r2sq = r2 * r2;
            float alpha = std::acos((sep * sep + r1sq - r2sq) / (2.f * sep * r1));
            float beta = std::acos((sep * sep + r2sq - r1sq) / (2.f * sep * r2));
            float part = -sep + r1 + r2;
            float area = r1sq * alpha + r2sq * beta - 0.5f * std::sqrt(part * (sep + r1 - r2) * (sep - r1 + r2) * (sep + r1 + r2));

            return area / (M_PI * r1sq);
        };

    float probability = overlap_ratio(spread_r, tgt_r, d);

    if (hitchance_out)
        *hitchance_out = std::clamp(probability, 0.f, 1.f);

    rage.restore.restore(rage.player);

    return probability >= chance;
}
 
Last edited:
Rookie HvHer
User ID
59772
Messages
38
Reactions
11
Level
8
Cracking Up Lol GIF by STRAPPED!
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Top