C++ Камера прыгает куда то

Пользователь
Статус
Оффлайн
Регистрация
5 Июл 2022
Сообщения
993
Реакции[?]
86
Поинты[?]
23K
Добрый день, столкнулся с такой проблемой, что при стрельбе, камера улетает куда - то. cs go. Пишу сюда, потому что думаю, что проблема, именно в каких то мб расчетах. Если выразился неправильно, не обессудьте
C++:
#include "aimbot.hpp"
#include "../helpers/math.hpp"
#include "../menu.hpp"
#include "../helpers/input.hpp"
#include "autowall.hpp"

#include <chrono>
std::map<const char*, HMODULE> modules;


HMODULE GetModule(const char* name)
{
    if (!modules.count(name) || !modules[name])
        modules[name] = GetModuleHandleA(name);

    return modules[name];
}

std::uint8_t* PatternScan2(const char* module_name, const char* signature)
{
    auto module = GetModule(module_name);

    static auto pattern_to_byte = [](const char* pattern) {
        auto bytes = std::vector<int>{};
        auto start = const_cast<char*>(pattern);
        auto end = const_cast<char*>(pattern) + strlen(pattern);

        for (auto current = start; current < end; ++current) {
            if (*current == '?') {
                ++current;
                if (*current == '?')
                    ++current;
                bytes.push_back(-1);
            }
            else {
                bytes.push_back(strtoul(current, &current, 16));
            }
        }
        return bytes;
    };

    auto dosHeader = (PIMAGE_DOS_HEADER)module;
    auto ntHeaders = (PIMAGE_NT_HEADERS)((std::uint8_t*)module + dosHeader->e_lfanew);

    auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage;
    auto patternBytes = pattern_to_byte(signature);
    auto scanBytes = reinterpret_cast<std::uint8_t*>(module);

    auto s = patternBytes.size();
    auto d = patternBytes.data();

    for (auto i = 0ul; i < sizeOfImage - s; ++i) {
        bool found = true;
        for (auto j = 0ul; j < s; ++j) {
            if (scanBytes[i + j] != d[j] && d[j] != -1) {
                found = false;
                break;
            }
        }
        if (found) {
            return &scanBytes[i];
        }
    }
    return nullptr;
}

float CLegitbot::GetFovToPlayer(QAngle viewAngle, QAngle aimAngle)
{
    QAngle delta = aimAngle - viewAngle;
    Math::FixAngles(delta);
    return sqrtf(powf(delta.x, 2.0f) + powf(delta.y, 2.0f)); /// (powf(delta.x, 2.0f) + powf(delta.y, 2.0f));
}

bool CLegitbot::IsLineGoesThroughSmoke(Vector startPos, Vector endPos)
{
    static auto LineGoesThroughSmokeFn = (bool(*)(Vector, Vector))PatternScan2("client.dll", "55 8B EC 83 EC 08 8B 15 ? ? ? ? 0F 57 C0");
    return LineGoesThroughSmokeFn(startPos, endPos);
}

bool CLegitbot::IsRcs()
{
    if (!g_LocalPlayer) return false;
    return g_LocalPlayer->m_iShotsFired() >= settings.rcs.start + 1;
}

bool CLegitbot::IsEnabled(CUserCmd* cmd)
{
    if (!g_EngineClient->IsInGame() || !g_LocalPlayer)
        return false;

    if (!g_LocalPlayer->IsAlive())
        return false;

    auto weapon = g_LocalPlayer->m_hActiveWeapon();
    if (!weapon || !weapon->IsGun())
        return false;

    settings = g_Options.aim_settings[weapon->m_iItemDefinitionIndex()].legit;

    if (!settings.enabled)
        return false;

    //if (!settings.enabled || !(cmd->buttons & IN_ATTACK)) {
        //return false;

    if (!weapon->HasBullets())
        return false;

    return (cmd->buttons & IN_ATTACK);

    return (cmd->buttons & IN_ATTACK) || (settings.autofire.enabled && GetAsyncKeyState(settings.autofire.hotkey));
}

void CLegitbot::Smooth(QAngle currentAngle, QAngle aimAngle, QAngle& angle)
{
    auto smooth_value = max(1.0f, settings.smooth);

    Vector current, aim;

    Math::AngleVectors(currentAngle, current);
    Math::AngleVectors(aimAngle, aim);

    const Vector delta = aim - current;
    const Vector smoothed = current + delta / smooth_value;

    Math::VectorAngles(smoothed, angle);
}

void CLegitbot::RCS(QAngle& angle, C_BasePlayer* target, CUserCmd* cmd)
{
    if (!settings.rcs.enabled || shotsFired < settings.rcs.start - 30)
        return;

    if (!settings.rcs.x && !settings.rcs.y)
        return;

    auto x = settings.rcs.x;
    auto y = settings.rcs.y;

    static auto weapon_recoil_scale = g_CVar->FindVar("weapon_recoil_scale");
    float scale = weapon_recoil_scale->GetFloat();

    if (scale != 2.f)
    {
        x = scale * x / 2.f;
        y = scale * y / 2.f;
    }

    x = scale *= 1.26f;
    y = scale;

    if (x <= 0 && y <= 0)
        return;

    QAngle punch = { };

    if (target)
        punch = { current_punch.x * x,  current_punch.y * y, 0 };
    else if (settings.rcs.type == 0)
        punch = { (current_punch.x - last_punch.x) * x, (current_punch.y - last_punch.y) * y, 0 };

    if ((punch.x != 0.f || punch.y != 0.f) && g_LocalPlayer->m_aimPunchAngle().z == 0.f)
    {
        angle -= punch;
        angle.Normalized();
    }

    last_corrected = punch;
}

/*void CLegitbot::RCS(QAngle& angle, C_BasePlayer* target)
{
    if (!settings.rcs.enabled || !IsRcs()) {
        return;
    }
    if (settings.rcs.x == 0 && settings.rcs.y == 0) {
        return;
    }
    if (target) {
        QAngle punch = g_LocalPlayer->m_aimPunchAngle();
        angle.x -= punch.x * (settings.rcs.x / 50.f);
        angle.y -= punch.y * (settings.rcs.y / 50.f);
    }
    else if (settings.rcs.type == 0) {
        QAngle NewPunch = { current_punch.x - last_punch.x, current_punch.y - last_punch.y, 0 };
        angle.x -= NewPunch.x * (settings.rcs.x / 50.f);
        angle.y -= NewPunch.y* (settings.rcs.y / 50.f);
    }
    Math::FixAngles(angle);
}*/

/*void CLegitbot::RCS(QAngle& angle, C_BasePlayer* target)
{
    if (!g_LocalPlayer)
        return;
    if (!settings.rcs.enabled || !IsRcs()) {
        return;
    }
    if (settings.rcs.x == 0 && settings.rcs.y == 0) {
        return;
    }
    if (target) {
        QAngle punch = g_LocalPlayer->m_aimPunchAngle();
        float x = settings.rcs.x * 0.02f;
        float y = settings.rcs.y * 0.02f;

        angle.x -= punch.x * x;
        angle.y -= punch.y * y;
    }
    Math::Normalize3(angle);
    Math::ClampAngles(angle);
}*/

bool CLegitbot::IsSilent()
{
    if (settings.silent2 == 2)
        return !(shotsFired > 0 || !settings.silent2 || !settings.silent_fov);
    if (settings.silent2 == 1)
        return !(!settings.silent2 || !settings.silent_fov);
    if (settings.silent2 == 0)
        return !(shotsFired > 0 || !settings.silent2 || !settings.silent_fov);
}

float CLegitbot::GetFov()
{
    if (IsSilent())
        return settings.silent_fov;

    return settings.fov;
}

bool CLegitbot::autoweapon() {
    if (!g_LocalPlayer->m_hActiveWeapon())
        return false;
    if (!g_LocalPlayer->IsNotTarget())
        return false;
    if (g_LocalPlayer->m_hActiveWeapon()->IsGrenade())
        return false;
    if (g_LocalPlayer->m_hActiveWeapon()->IsKnife())
        return false;
    if (g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_TASER ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_FISTS ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_BREACHCHARGE ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_TABLET ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_MELEE ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_AXE ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_HAMMER ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_KNIFE_GHOST ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_FIREBOMB ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_DIVERSION ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_FRAG_GRENADE ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_C4 ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_HEALTHSHOT
        )
        return false;

    Weapon::current_weapon = g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex();
    return true;
}

C_BasePlayer* CLegitbot::GetClosestPlayer(CUserCmd* cmd, int& bestBone, float& bestFov, QAngle& bestAngles)
{
    if (target && !kill_delay && settings.kill_delay > 0 && !target->IsAlive())
    {
        target = nullptr;
        kill_delay = true;
        kill_delay_time = int(GetTickCount()) + settings.kill_delay;
    }
    if (kill_delay)
    {
        if (kill_delay_time <= int(GetTickCount()))
            kill_delay = false;
        else
            return nullptr;
    }

    target = nullptr;

    std::vector<int> hitboxes;


    if (settings.hitboxes.head) {
        hitboxes.push_back(HITBOX_HEAD);
    }
    /////////////////////////////

    if (settings.hitboxes.neck)

        hitboxes.push_back(HITBOX_NECK);

    if (settings.hitboxes.belly)
        hitboxes.push_back(HITBOX_STOMACH);

    if (settings.hitboxes.chest)
    {
        hitboxes.push_back(HITBOX_CHEST);
        hitboxes.push_back(HITBOX_LOWER_CHEST);
        hitboxes.push_back(HITBOX_UPPER_CHEST);
    }

    /*if (settings.hitboxes.chest)
    {
        hitboxes.emplace_back(HITBOX_UPPER_CHEST);
        hitboxes.emplace_back(HITBOX_CHEST);
        hitboxes.emplace_back(HITBOX_LOWER_CHEST);
    }*/

    if (settings.hitboxes.hands)
    {
        hitboxes.push_back(HITBOX_RIGHT_UPPER_ARM);
        hitboxes.push_back(HITBOX_RIGHT_FOREARM);

        hitboxes.push_back(HITBOX_LEFT_UPPER_ARM);
        hitboxes.push_back(HITBOX_LEFT_FOREARM);

        hitboxes.push_back(HITBOX_RIGHT_HAND);
        hitboxes.push_back(HITBOX_LEFT_HAND);
    }

    /*if (settings.hitboxes.hands)
    {
        hitboxes.emplace_back(HITBOX_LEFT_FOREARM);
        hitboxes.emplace_back(HITBOX_LEFT_HAND);
        hitboxes.emplace_back(HITBOX_LEFT_UPPER_ARM);

        hitboxes.emplace_back(HITBOX_RIGHT_FOREARM);
        hitboxes.emplace_back(HITBOX_RIGHT_HAND);
        hitboxes.emplace_back(HITBOX_RIGHT_UPPER_ARM);
    }*/

    if (settings.hitboxes.legs)
    {
        hitboxes.push_back(HITBOX_LEFT_FOOT);
        hitboxes.push_back(HITBOX_RIGHT_FOOT);

        hitboxes.push_back(HITBOX_LEFT_THIGH);
        hitboxes.push_back(HITBOX_RIGHT_THIGH);

        hitboxes.push_back(HITBOX_LEFT_CALF);
        hitboxes.push_back(HITBOX_RIGHT_CALF);
    }

    /*if (settings.hitboxes.legs)
    {
        hitboxes.emplace_back(HITBOX_LEFT_FOOT);
        hitboxes.emplace_back(HITBOX_LEFT_CALF);
        hitboxes.emplace_back(HITBOX_LEFT_THIGH);

        hitboxes.emplace_back(HITBOX_RIGHT_FOOT);
        hitboxes.emplace_back(HITBOX_LEFT_CALF);
        hitboxes.emplace_back(HITBOX_LEFT_THIGH);
    }*/
    

    const Vector eyePos = g_LocalPlayer->GetEyePos();

    for (auto i = 1; i <= g_GlobalVars->maxClients; i++) //g_GlobalVars->maxClients
    {
        C_BasePlayer* player = C_BasePlayer::GetPlayerByIndex(i);

        if (!player || !player->IsAlive() || !player->IsPlayer() || player->m_bGunGameImmunity())
            continue;

        //if (!player->IsEnemy())
            //continue;

        for (const auto hitbox : hitboxes)
        {
            Vector hitboxPos = player->GetHitboxPos(hitbox);
            QAngle ang;
            Math::VectorAngles(hitboxPos - eyePos, ang);
            const float fov = GetFovToPlayer(cmd->viewangles + last_punch * 2.f, ang);

            if (fov > GetFov())
                continue;

            if (!g_LocalPlayer->CanSeePlayer(player, player->abs_origin()))
                continue;

            if (settings.smoke_check && IsLineGoesThroughSmoke(eyePos, hitboxPos))
                continue;

            if (bestFov > fov)
            {
                bestBone = hitbox;
                bestAngles = ang;
                bestFov = fov;
                target = player;
            }
        }
    }

    return target;
}

void CLegitbot::Run(CUserCmd* cmd)
{
    if (int(GetTickCount()) > lastShotTick + 50)
        shotsFired = 0;

    if (!IsEnabled(cmd))
    {
        last_punch = { 0, 0, 0 };
        shot_delay = false;
        kill_delay = false;
        target = nullptr;
        return;
    }

    auto weapon = g_LocalPlayer->m_hActiveWeapon().Get();
    if (!weapon)
        return;

    auto weapon_data = weapon->GetCSWeaponData();
    if (!weapon_data)
        return;

    if (settings.flash_check && g_LocalPlayer->IsFlashed())
        return;

    auto angles = cmd->viewangles;
    const auto current = angles;

    float fov = FLT_MAX;

    int bestBone = -1;

    if (GetClosestPlayer(cmd, bestBone, fov, angles))
    {
        if ((!settings.silent2 || settings.silent2 == 2) && !shot_delay && settings.shot_delay > 0 && !shotsFired)
        {
            shot_delay = true;
            shot_delay_time = int(GetTickCount()) + settings.shot_delay;
        }

        if (fov <= .5)
            shot_delay = false;

        if (shot_delay && shot_delay_time <= int(GetTickCount()))
            shot_delay = false;

        if (shot_delay)
            cmd->buttons &= ~IN_ATTACK;

        if (settings.autofire.enabled && GetAsyncKeyState(settings.autofire.hotkey))
            cmd->buttons |= IN_ATTACK;
    }

    current_punch = g_LocalPlayer->m_aimPunchAngle();
    {
        if (cmd->buttons & IN_ATTACK)
            RCS(angles, target ,cmd);
    }
    last_punch = current_punch;

    if (!IsSilent() && target)
        Smooth(current, angles, angles);

    Math::FixAngles(angles);
    cmd->viewangles = angles;
    if (!IsSilent())
        g_EngineClient->SetViewAngles(&angles);

    if (g_LocalPlayer->m_hActiveWeapon()->IsPistol() && settings.autopistol)
    {
        const float server_time = g_LocalPlayer->m_nTickBase() * g_GlobalVars->interval_per_tick;
        const float next_shot = g_LocalPlayer->m_hActiveWeapon()->m_flNextPrimaryAttack() - server_time;

        if (next_shot > 0)
            cmd->buttons &= ~IN_ATTACK;
    }

    if (cmd->buttons & IN_ATTACK)
    {
        lastShotTick = GetTickCount();
        shotsFired + 3;
    }
}
 
Эксперт
Статус
Оффлайн
Регистрация
30 Дек 2019
Сообщения
1,970
Реакции[?]
958
Поинты[?]
19K
Добрый день, столкнулся с такой проблемой, что при стрельбе, камера улетает куда - то. cs go. Пишу сюда, потому что думаю, что проблема, именно в каких то мб расчетах. Если выразился неправильно, не обессудьте
C++:
#include "aimbot.hpp"
#include "../helpers/math.hpp"
#include "../menu.hpp"
#include "../helpers/input.hpp"
#include "autowall.hpp"

#include <chrono>
std::map<const char*, HMODULE> modules;


HMODULE GetModule(const char* name)
{
    if (!modules.count(name) || !modules[name])
        modules[name] = GetModuleHandleA(name);

    return modules[name];
}

std::uint8_t* PatternScan2(const char* module_name, const char* signature)
{
    auto module = GetModule(module_name);

    static auto pattern_to_byte = [](const char* pattern) {
        auto bytes = std::vector<int>{};
        auto start = const_cast<char*>(pattern);
        auto end = const_cast<char*>(pattern) + strlen(pattern);

        for (auto current = start; current < end; ++current) {
            if (*current == '?') {
                ++current;
                if (*current == '?')
                    ++current;
                bytes.push_back(-1);
            }
            else {
                bytes.push_back(strtoul(current, &current, 16));
            }
        }
        return bytes;
    };

    auto dosHeader = (PIMAGE_DOS_HEADER)module;
    auto ntHeaders = (PIMAGE_NT_HEADERS)((std::uint8_t*)module + dosHeader->e_lfanew);

    auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage;
    auto patternBytes = pattern_to_byte(signature);
    auto scanBytes = reinterpret_cast<std::uint8_t*>(module);

    auto s = patternBytes.size();
    auto d = patternBytes.data();

    for (auto i = 0ul; i < sizeOfImage - s; ++i) {
        bool found = true;
        for (auto j = 0ul; j < s; ++j) {
            if (scanBytes[i + j] != d[j] && d[j] != -1) {
                found = false;
                break;
            }
        }
        if (found) {
            return &scanBytes[i];
        }
    }
    return nullptr;
}

float CLegitbot::GetFovToPlayer(QAngle viewAngle, QAngle aimAngle)
{
    QAngle delta = aimAngle - viewAngle;
    Math::FixAngles(delta);
    return sqrtf(powf(delta.x, 2.0f) + powf(delta.y, 2.0f)); /// (powf(delta.x, 2.0f) + powf(delta.y, 2.0f));
}

bool CLegitbot::IsLineGoesThroughSmoke(Vector startPos, Vector endPos)
{
    static auto LineGoesThroughSmokeFn = (bool(*)(Vector, Vector))PatternScan2("client.dll", "55 8B EC 83 EC 08 8B 15 ? ? ? ? 0F 57 C0");
    return LineGoesThroughSmokeFn(startPos, endPos);
}

bool CLegitbot::IsRcs()
{
    if (!g_LocalPlayer) return false;
    return g_LocalPlayer->m_iShotsFired() >= settings.rcs.start + 1;
}

bool CLegitbot::IsEnabled(CUserCmd* cmd)
{
    if (!g_EngineClient->IsInGame() || !g_LocalPlayer)
        return false;

    if (!g_LocalPlayer->IsAlive())
        return false;

    auto weapon = g_LocalPlayer->m_hActiveWeapon();
    if (!weapon || !weapon->IsGun())
        return false;

    settings = g_Options.aim_settings[weapon->m_iItemDefinitionIndex()].legit;

    if (!settings.enabled)
        return false;

    //if (!settings.enabled || !(cmd->buttons & IN_ATTACK)) {
        //return false;

    if (!weapon->HasBullets())
        return false;

    return (cmd->buttons & IN_ATTACK);

    return (cmd->buttons & IN_ATTACK) || (settings.autofire.enabled && GetAsyncKeyState(settings.autofire.hotkey));
}

void CLegitbot::Smooth(QAngle currentAngle, QAngle aimAngle, QAngle& angle)
{
    auto smooth_value = max(1.0f, settings.smooth);

    Vector current, aim;

    Math::AngleVectors(currentAngle, current);
    Math::AngleVectors(aimAngle, aim);

    const Vector delta = aim - current;
    const Vector smoothed = current + delta / smooth_value;

    Math::VectorAngles(smoothed, angle);
}

void CLegitbot::RCS(QAngle& angle, C_BasePlayer* target, CUserCmd* cmd)
{
    if (!settings.rcs.enabled || shotsFired < settings.rcs.start - 30)
        return;

    if (!settings.rcs.x && !settings.rcs.y)
        return;

    auto x = settings.rcs.x;
    auto y = settings.rcs.y;

    static auto weapon_recoil_scale = g_CVar->FindVar("weapon_recoil_scale");
    float scale = weapon_recoil_scale->GetFloat();

    if (scale != 2.f)
    {
        x = scale * x / 2.f;
        y = scale * y / 2.f;
    }

    x = scale *= 1.26f;
    y = scale;

    if (x <= 0 && y <= 0)
        return;

    QAngle punch = { };

    if (target)
        punch = { current_punch.x * x,  current_punch.y * y, 0 };
    else if (settings.rcs.type == 0)
        punch = { (current_punch.x - last_punch.x) * x, (current_punch.y - last_punch.y) * y, 0 };

    if ((punch.x != 0.f || punch.y != 0.f) && g_LocalPlayer->m_aimPunchAngle().z == 0.f)
    {
        angle -= punch;
        angle.Normalized();
    }

    last_corrected = punch;
}

/*void CLegitbot::RCS(QAngle& angle, C_BasePlayer* target)
{
    if (!settings.rcs.enabled || !IsRcs()) {
        return;
    }
    if (settings.rcs.x == 0 && settings.rcs.y == 0) {
        return;
    }
    if (target) {
        QAngle punch = g_LocalPlayer->m_aimPunchAngle();
        angle.x -= punch.x * (settings.rcs.x / 50.f);
        angle.y -= punch.y * (settings.rcs.y / 50.f);
    }
    else if (settings.rcs.type == 0) {
        QAngle NewPunch = { current_punch.x - last_punch.x, current_punch.y - last_punch.y, 0 };
        angle.x -= NewPunch.x * (settings.rcs.x / 50.f);
        angle.y -= NewPunch.y* (settings.rcs.y / 50.f);
    }
    Math::FixAngles(angle);
}*/

/*void CLegitbot::RCS(QAngle& angle, C_BasePlayer* target)
{
    if (!g_LocalPlayer)
        return;
    if (!settings.rcs.enabled || !IsRcs()) {
        return;
    }
    if (settings.rcs.x == 0 && settings.rcs.y == 0) {
        return;
    }
    if (target) {
        QAngle punch = g_LocalPlayer->m_aimPunchAngle();
        float x = settings.rcs.x * 0.02f;
        float y = settings.rcs.y * 0.02f;

        angle.x -= punch.x * x;
        angle.y -= punch.y * y;
    }
    Math::Normalize3(angle);
    Math::ClampAngles(angle);
}*/

bool CLegitbot::IsSilent()
{
    if (settings.silent2 == 2)
        return !(shotsFired > 0 || !settings.silent2 || !settings.silent_fov);
    if (settings.silent2 == 1)
        return !(!settings.silent2 || !settings.silent_fov);
    if (settings.silent2 == 0)
        return !(shotsFired > 0 || !settings.silent2 || !settings.silent_fov);
}

float CLegitbot::GetFov()
{
    if (IsSilent())
        return settings.silent_fov;

    return settings.fov;
}

bool CLegitbot::autoweapon() {
    if (!g_LocalPlayer->m_hActiveWeapon())
        return false;
    if (!g_LocalPlayer->IsNotTarget())
        return false;
    if (g_LocalPlayer->m_hActiveWeapon()->IsGrenade())
        return false;
    if (g_LocalPlayer->m_hActiveWeapon()->IsKnife())
        return false;
    if (g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_TASER ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_FISTS ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_BREACHCHARGE ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_TABLET ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_MELEE ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_AXE ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_HAMMER ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_KNIFE_GHOST ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_FIREBOMB ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_DIVERSION ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_FRAG_GRENADE ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_C4 ||
        g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex() == WEAPON_HEALTHSHOT
        )
        return false;

    Weapon::current_weapon = g_LocalPlayer->m_hActiveWeapon()->m_iItemDefinitionIndex();
    return true;
}

C_BasePlayer* CLegitbot::GetClosestPlayer(CUserCmd* cmd, int& bestBone, float& bestFov, QAngle& bestAngles)
{
    if (target && !kill_delay && settings.kill_delay > 0 && !target->IsAlive())
    {
        target = nullptr;
        kill_delay = true;
        kill_delay_time = int(GetTickCount()) + settings.kill_delay;
    }
    if (kill_delay)
    {
        if (kill_delay_time <= int(GetTickCount()))
            kill_delay = false;
        else
            return nullptr;
    }

    target = nullptr;

    std::vector<int> hitboxes;


    if (settings.hitboxes.head) {
        hitboxes.push_back(HITBOX_HEAD);
    }
    /////////////////////////////

    if (settings.hitboxes.neck)

        hitboxes.push_back(HITBOX_NECK);

    if (settings.hitboxes.belly)
        hitboxes.push_back(HITBOX_STOMACH);

    if (settings.hitboxes.chest)
    {
        hitboxes.push_back(HITBOX_CHEST);
        hitboxes.push_back(HITBOX_LOWER_CHEST);
        hitboxes.push_back(HITBOX_UPPER_CHEST);
    }

    /*if (settings.hitboxes.chest)
    {
        hitboxes.emplace_back(HITBOX_UPPER_CHEST);
        hitboxes.emplace_back(HITBOX_CHEST);
        hitboxes.emplace_back(HITBOX_LOWER_CHEST);
    }*/

    if (settings.hitboxes.hands)
    {
        hitboxes.push_back(HITBOX_RIGHT_UPPER_ARM);
        hitboxes.push_back(HITBOX_RIGHT_FOREARM);

        hitboxes.push_back(HITBOX_LEFT_UPPER_ARM);
        hitboxes.push_back(HITBOX_LEFT_FOREARM);

        hitboxes.push_back(HITBOX_RIGHT_HAND);
        hitboxes.push_back(HITBOX_LEFT_HAND);
    }

    /*if (settings.hitboxes.hands)
    {
        hitboxes.emplace_back(HITBOX_LEFT_FOREARM);
        hitboxes.emplace_back(HITBOX_LEFT_HAND);
        hitboxes.emplace_back(HITBOX_LEFT_UPPER_ARM);

        hitboxes.emplace_back(HITBOX_RIGHT_FOREARM);
        hitboxes.emplace_back(HITBOX_RIGHT_HAND);
        hitboxes.emplace_back(HITBOX_RIGHT_UPPER_ARM);
    }*/

    if (settings.hitboxes.legs)
    {
        hitboxes.push_back(HITBOX_LEFT_FOOT);
        hitboxes.push_back(HITBOX_RIGHT_FOOT);

        hitboxes.push_back(HITBOX_LEFT_THIGH);
        hitboxes.push_back(HITBOX_RIGHT_THIGH);

        hitboxes.push_back(HITBOX_LEFT_CALF);
        hitboxes.push_back(HITBOX_RIGHT_CALF);
    }

    /*if (settings.hitboxes.legs)
    {
        hitboxes.emplace_back(HITBOX_LEFT_FOOT);
        hitboxes.emplace_back(HITBOX_LEFT_CALF);
        hitboxes.emplace_back(HITBOX_LEFT_THIGH);

        hitboxes.emplace_back(HITBOX_RIGHT_FOOT);
        hitboxes.emplace_back(HITBOX_LEFT_CALF);
        hitboxes.emplace_back(HITBOX_LEFT_THIGH);
    }*/
   

    const Vector eyePos = g_LocalPlayer->GetEyePos();

    for (auto i = 1; i <= g_GlobalVars->maxClients; i++) //g_GlobalVars->maxClients
    {
        C_BasePlayer* player = C_BasePlayer::GetPlayerByIndex(i);

        if (!player || !player->IsAlive() || !player->IsPlayer() || player->m_bGunGameImmunity())
            continue;

        //if (!player->IsEnemy())
            //continue;

        for (const auto hitbox : hitboxes)
        {
            Vector hitboxPos = player->GetHitboxPos(hitbox);
            QAngle ang;
            Math::VectorAngles(hitboxPos - eyePos, ang);
            const float fov = GetFovToPlayer(cmd->viewangles + last_punch * 2.f, ang);

            if (fov > GetFov())
                continue;

            if (!g_LocalPlayer->CanSeePlayer(player, player->abs_origin()))
                continue;

            if (settings.smoke_check && IsLineGoesThroughSmoke(eyePos, hitboxPos))
                continue;

            if (bestFov > fov)
            {
                bestBone = hitbox;
                bestAngles = ang;
                bestFov = fov;
                target = player;
            }
        }
    }

    return target;
}

void CLegitbot::Run(CUserCmd* cmd)
{
    if (int(GetTickCount()) > lastShotTick + 50)
        shotsFired = 0;

    if (!IsEnabled(cmd))
    {
        last_punch = { 0, 0, 0 };
        shot_delay = false;
        kill_delay = false;
        target = nullptr;
        return;
    }

    auto weapon = g_LocalPlayer->m_hActiveWeapon().Get();
    if (!weapon)
        return;

    auto weapon_data = weapon->GetCSWeaponData();
    if (!weapon_data)
        return;

    if (settings.flash_check && g_LocalPlayer->IsFlashed())
        return;

    auto angles = cmd->viewangles;
    const auto current = angles;

    float fov = FLT_MAX;

    int bestBone = -1;

    if (GetClosestPlayer(cmd, bestBone, fov, angles))
    {
        if ((!settings.silent2 || settings.silent2 == 2) && !shot_delay && settings.shot_delay > 0 && !shotsFired)
        {
            shot_delay = true;
            shot_delay_time = int(GetTickCount()) + settings.shot_delay;
        }

        if (fov <= .5)
            shot_delay = false;

        if (shot_delay && shot_delay_time <= int(GetTickCount()))
            shot_delay = false;

        if (shot_delay)
            cmd->buttons &= ~IN_ATTACK;

        if (settings.autofire.enabled && GetAsyncKeyState(settings.autofire.hotkey))
            cmd->buttons |= IN_ATTACK;
    }

    current_punch = g_LocalPlayer->m_aimPunchAngle();
    {
        if (cmd->buttons & IN_ATTACK)
            RCS(angles, target ,cmd);
    }
    last_punch = current_punch;

    if (!IsSilent() && target)
        Smooth(current, angles, angles);

    Math::FixAngles(angles);
    cmd->viewangles = angles;
    if (!IsSilent())
        g_EngineClient->SetViewAngles(&angles);

    if (g_LocalPlayer->m_hActiveWeapon()->IsPistol() && settings.autopistol)
    {
        const float server_time = g_LocalPlayer->m_nTickBase() * g_GlobalVars->interval_per_tick;
        const float next_shot = g_LocalPlayer->m_hActiveWeapon()->m_flNextPrimaryAttack() - server_time;

        if (next_shot > 0)
            cmd->buttons &= ~IN_ATTACK;
    }

    if (cmd->buttons & IN_ATTACK)
    {
        lastShotTick = GetTickCount();
        shotsFired + 3;
    }
}
видос запиши, откуда мы знаем что и как у тебя прыгает
 
Пользователь
Статус
Оффлайн
Регистрация
5 Июл 2022
Сообщения
993
Реакции[?]
86
Поинты[?]
23K
C++:
namespace Math
{
    void FixAngles(QAngle& angles)
    {
        Normalize3(angles);
        ClampAngles(angles);
    }
    //--------------------------------------------------------------------------------
    float VectorDistance(const Vector& v1, const Vector& v2)
    {
        return FASTSQRT(pow(v1.x - v2.x, 2) + pow(v1.y - v2.y, 2) + pow(v1.z - v2.z, 2));
    }
    //--------------------------------------------------------------------------------
    QAngle CalcAngle(const Vector& src, const Vector& dst)
    {
        QAngle vAngle;
        Vector delta((src.x - dst.x), (src.y - dst.y), (src.z - dst.z));
        double hyp = sqrt(delta.x*delta.x + delta.y*delta.y);

        vAngle.x = float(atanf(float(delta.z / hyp)) * 57.295779513082f);
        vAngle.y = float(atanf(float(delta.y / delta.x)) * 57.295779513082f);
        vAngle.z = 0.0f;

        if (delta.x >= 0.0)
            vAngle.y += 180.0f;

        return vAngle;
    }
    //--------------------------------------------------------------------------------
    float GetFOV(const QAngle& viewAngle, const QAngle& aimAngle)
    {
        Vector ang, aim;

        AngleVectors(viewAngle, aim);
        AngleVectors(aimAngle, ang);

        return RAD2DEG(acos(aim.Dot(ang) / aim.LengthSqr()));
    }
    //--------------------------------------------------------------------------------
    void ClampAngles(QAngle& angles)
    {
        if (angles.x > 89.0f) angles.x = 89.0f;
        else if (angles.x < -89.0f) angles.x = -89.0f;

        if (angles.y > 180.0f) angles.y = 180.0f;
        else if (angles.y < -180.0f) angles.y = -180.0f;

        angles.z = 0;
    }
    //--------------------------------------------------------------------------------
    void VectorTransform(const Vector& in1, const matrix3x4_t& in2, Vector& out)
    {
        out[0] = in1.Dot(in2[0]) + in2[0][3];
        out[1] = in1.Dot(in2[1]) + in2[1][3];
        out[2] = in1.Dot(in2[2]) + in2[2][3];
    }
    //--------------------------------------------------------------------------------
    void AngleVectors(const QAngle &angles, Vector& forward)
    {
        float    sp, sy, cp, cy;

        DirectX::XMScalarSinCos(&sp, &cp, DEG2RAD(angles[0]));
        DirectX::XMScalarSinCos(&sy, &cy, DEG2RAD(angles[1]));

        forward.x = cp * cy;
        forward.y = cp * sy;
        forward.z = -sp;
    }
    //--------------------------------------------------------------------------------
    void TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, C_BasePlayer* ignore, trace_t* ptr)
    {
        Ray_t ray;
        ray.Init(vecAbsStart, vecAbsEnd);
        CTraceFilter filter;
        filter.pSkip = ignore;

        g_EngineTrace->TraceRay(ray, mask, &filter, ptr);
    }
    //--------------------------------------------------------------------------------
    void AngleVectors(const QAngle &angles, Vector& forward, Vector& right, Vector& up)
    {
        float sr, sp, sy, cr, cp, cy;

        DirectX::XMScalarSinCos(&sp, &cp, DEG2RAD(angles[0]));
        DirectX::XMScalarSinCos(&sy, &cy, DEG2RAD(angles[1]));
        DirectX::XMScalarSinCos(&sr, &cr, DEG2RAD(angles[2]));

        forward.x = (cp * cy);
        forward.y = (cp * sy);
        forward.z = (-sp);
        right.x = (-1 * sr * sp * cy + -1 * cr * -sy);
        right.y = (-1 * sr * sp * sy + -1 * cr *  cy);
        right.z = (-1 * sr * cp);
        up.x = (cr * sp * cy + -sr * -sy);
        up.y = (cr * sp * sy + -sr * cy);
        up.z = (cr * cp);
    }
    //--------------------------------------------------------------------------------
    void VectorAngles(const Vector& forward, QAngle& angles)
    {
        float    tmp, yaw, pitch;

        if (forward[1] == 0 && forward[0] == 0) {
            yaw = 0;
            if (forward[2] > 0)
                pitch = 270;
            else
                pitch = 90;
        }
        else {
            yaw = (atan2(forward[1], forward[0]) * 180 / DirectX::XM_PI);
            if (yaw < 0)
                yaw += 360;

            tmp = sqrt(forward[0] * forward[0] + forward[1] * forward[1]);
            pitch = (atan2(-forward[2], tmp) * 180 / DirectX::XM_PI);
            if (pitch < 0)
                pitch += 360;
        }

        angles[0] = pitch;
        angles[1] = yaw;
        angles[2] = 0;
    }
    //--------------------------------------------------------------------------------
    static bool screen_transform(const Vector& in, Vector& out)
    {
        static auto& w2sMatrix = g_EngineClient->WorldToScreenMatrix();

        out.x = w2sMatrix.m[0][0] * in.x + w2sMatrix.m[0][1] * in.y + w2sMatrix.m[0][2] * in.z + w2sMatrix.m[0][3];
        out.y = w2sMatrix.m[1][0] * in.x + w2sMatrix.m[1][1] * in.y + w2sMatrix.m[1][2] * in.z + w2sMatrix.m[1][3];
        out.z = 0.0f;

        float w = w2sMatrix.m[3][0] * in.x + w2sMatrix.m[3][1] * in.y + w2sMatrix.m[3][2] * in.z + w2sMatrix.m[3][3];

        if (w < 0.001f) {
            out.x *= 100000;
            out.y *= 100000;
            return false;
        }

        out.x /= w;
        out.y /= w;

        return true;
    }
    //--------------------------------------------------------------------------------
    bool WorldToScreen(const Vector& in, Vector& out)
    {
        if (screen_transform(in, out)) {
            int w, h;
            g_EngineClient->GetScreenSize(w, h);

            out.x = (w / 2.0f) + (out.x * w) / 2.0f;
            out.y = (h / 2.0f) - (out.y * h) / 2.0f;

            return true;
        }
        return false;
    }
    //--------------------------------------------------------------------------------
}
Уже два дня кручу верчу, но нихуя не чиню.
 
#include <brain>
Забаненный
Статус
Оффлайн
Регистрация
29 Сен 2020
Сообщения
588
Реакции[?]
99
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
C++:
namespace Math
{
    void FixAngles(QAngle& angles)
    {
        Normalize3(angles);
        ClampAngles(angles);
    }
    //--------------------------------------------------------------------------------
    float VectorDistance(const Vector& v1, const Vector& v2)
    {
        return FASTSQRT(pow(v1.x - v2.x, 2) + pow(v1.y - v2.y, 2) + pow(v1.z - v2.z, 2));
    }
    //--------------------------------------------------------------------------------
    QAngle CalcAngle(const Vector& src, const Vector& dst)
    {
        QAngle vAngle;
        Vector delta((src.x - dst.x), (src.y - dst.y), (src.z - dst.z));
        double hyp = sqrt(delta.x*delta.x + delta.y*delta.y);

        vAngle.x = float(atanf(float(delta.z / hyp)) * 57.295779513082f);
        vAngle.y = float(atanf(float(delta.y / delta.x)) * 57.295779513082f);
        vAngle.z = 0.0f;

        if (delta.x >= 0.0)
            vAngle.y += 180.0f;

        return vAngle;
    }
    //--------------------------------------------------------------------------------
    float GetFOV(const QAngle& viewAngle, const QAngle& aimAngle)
    {
        Vector ang, aim;

        AngleVectors(viewAngle, aim);
        AngleVectors(aimAngle, ang);

        return RAD2DEG(acos(aim.Dot(ang) / aim.LengthSqr()));
    }
    //--------------------------------------------------------------------------------
    void ClampAngles(QAngle& angles)
    {
        if (angles.x > 89.0f) angles.x = 89.0f;
        else if (angles.x < -89.0f) angles.x = -89.0f;

        if (angles.y > 180.0f) angles.y = 180.0f;
        else if (angles.y < -180.0f) angles.y = -180.0f;

        angles.z = 0;
    }
    //--------------------------------------------------------------------------------
    void VectorTransform(const Vector& in1, const matrix3x4_t& in2, Vector& out)
    {
        out[0] = in1.Dot(in2[0]) + in2[0][3];
        out[1] = in1.Dot(in2[1]) + in2[1][3];
        out[2] = in1.Dot(in2[2]) + in2[2][3];
    }
    //--------------------------------------------------------------------------------
    void AngleVectors(const QAngle &angles, Vector& forward)
    {
        float    sp, sy, cp, cy;

        DirectX::XMScalarSinCos(&sp, &cp, DEG2RAD(angles[0]));
        DirectX::XMScalarSinCos(&sy, &cy, DEG2RAD(angles[1]));

        forward.x = cp * cy;
        forward.y = cp * sy;
        forward.z = -sp;
    }
    //--------------------------------------------------------------------------------
    void TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, C_BasePlayer* ignore, trace_t* ptr)
    {
        Ray_t ray;
        ray.Init(vecAbsStart, vecAbsEnd);
        CTraceFilter filter;
        filter.pSkip = ignore;

        g_EngineTrace->TraceRay(ray, mask, &filter, ptr);
    }
    //--------------------------------------------------------------------------------
    void AngleVectors(const QAngle &angles, Vector& forward, Vector& right, Vector& up)
    {
        float sr, sp, sy, cr, cp, cy;

        DirectX::XMScalarSinCos(&sp, &cp, DEG2RAD(angles[0]));
        DirectX::XMScalarSinCos(&sy, &cy, DEG2RAD(angles[1]));
        DirectX::XMScalarSinCos(&sr, &cr, DEG2RAD(angles[2]));

        forward.x = (cp * cy);
        forward.y = (cp * sy);
        forward.z = (-sp);
        right.x = (-1 * sr * sp * cy + -1 * cr * -sy);
        right.y = (-1 * sr * sp * sy + -1 * cr *  cy);
        right.z = (-1 * sr * cp);
        up.x = (cr * sp * cy + -sr * -sy);
        up.y = (cr * sp * sy + -sr * cy);
        up.z = (cr * cp);
    }
    //--------------------------------------------------------------------------------
    void VectorAngles(const Vector& forward, QAngle& angles)
    {
        float    tmp, yaw, pitch;

        if (forward[1] == 0 && forward[0] == 0) {
            yaw = 0;
            if (forward[2] > 0)
                pitch = 270;
            else
                pitch = 90;
        }
        else {
            yaw = (atan2(forward[1], forward[0]) * 180 / DirectX::XM_PI);
            if (yaw < 0)
                yaw += 360;

            tmp = sqrt(forward[0] * forward[0] + forward[1] * forward[1]);
            pitch = (atan2(-forward[2], tmp) * 180 / DirectX::XM_PI);
            if (pitch < 0)
                pitch += 360;
        }

        angles[0] = pitch;
        angles[1] = yaw;
        angles[2] = 0;
    }
    //--------------------------------------------------------------------------------
    static bool screen_transform(const Vector& in, Vector& out)
    {
        static auto& w2sMatrix = g_EngineClient->WorldToScreenMatrix();

        out.x = w2sMatrix.m[0][0] * in.x + w2sMatrix.m[0][1] * in.y + w2sMatrix.m[0][2] * in.z + w2sMatrix.m[0][3];
        out.y = w2sMatrix.m[1][0] * in.x + w2sMatrix.m[1][1] * in.y + w2sMatrix.m[1][2] * in.z + w2sMatrix.m[1][3];
        out.z = 0.0f;

        float w = w2sMatrix.m[3][0] * in.x + w2sMatrix.m[3][1] * in.y + w2sMatrix.m[3][2] * in.z + w2sMatrix.m[3][3];

        if (w < 0.001f) {
            out.x *= 100000;
            out.y *= 100000;
            return false;
        }

        out.x /= w;
        out.y /= w;

        return true;
    }
    //--------------------------------------------------------------------------------
    bool WorldToScreen(const Vector& in, Vector& out)
    {
        if (screen_transform(in, out)) {
            int w, h;
            g_EngineClient->GetScreenSize(w, h);

            out.x = (w / 2.0f) + (out.x * w) / 2.0f;
            out.y = (h / 2.0f) - (out.y * h) / 2.0f;

            return true;
        }
        return false;
    }
    //--------------------------------------------------------------------------------
}
Уже два дня кручу верчу, но нихуя не чиню.
а почему ты создаешь тему тут ? когда есть специальный раздел который смотрят чаще.
 
Пользователь
Статус
Оффлайн
Регистрация
5 Июл 2022
Сообщения
993
Реакции[?]
86
Поинты[?]
23K
Эксперт
Статус
Оффлайн
Регистрация
30 Дек 2019
Сообщения
1,970
Реакции[?]
958
Поинты[?]
19K
Сверху Снизу