// aimbot.hpp
#pragma once
#include "../base/sdk/vectors.hpp"
#include "../base/driver/driver.hpp"
#include "../base/utils/settings.hpp"
#include <cmath>
#include "../base/sdk/sdk.hpp"

Vector3 PredictLocation(Vector3 target, Vector3 targetVelocity, float projectileSpeed, float projectileGravityScale, float distance)
{
    float horizontalTime = distance / projectileSpeed;
    float verticalTime = distance / projectileSpeed;

    target.x += targetVelocity.x * horizontalTime;
    target.y += targetVelocity.y * horizontalTime;
    target.z += targetVelocity.z * verticalTime +
        abs(-980 * projectileGravityScale) * 0.5f * (verticalTime * verticalTime);

    return target;
}

bool memory_event(Vector3 newpos)
{
    kernel->write_t<Vector3>(PawnData::PlayerController + 0x2C18, newpos); //WeaponOffsetCorrection 0x2bf0
    return true;
}

void memoryaim(uintptr_t targetmeshs, Vector2 target2d)
{
    Vector2 target{};
    float speedPercent = settings::aimbot.smoothsize;
    float smoothness = 100.0f - (speedPercent - 1.0f);
    if (smoothness < 1.0f) smoothness = 1.0f;

    float screen_center_x = static_cast<float>(Width) / 2;
    float screen_center_y = static_cast<float>(Height) / 2;

    if (target2d.x > screen_center_x) {
        target.x = -(screen_center_x - target2d.x) / smoothness;
        if (target.x + screen_center_x > screen_center_x * 2)
            target.x = 0;
    }
    else if (target2d.x < screen_center_x) {
        target.x = (target2d.x - screen_center_x) / smoothness;
        if (target.x + screen_center_x < 0)
            target.x = 0;
    }

    if (target2d.y > screen_center_y) {
        target.y = -(screen_center_y - target2d.y) / smoothness;
        if (target.y + screen_center_y > screen_center_y * 2)
            target.y = 0;
    }
    else if (target2d.y < screen_center_y) {
        target.y = (target2d.y - screen_center_y) / smoothness;
        if (target.y + screen_center_y < 0)
            target.y = 0;
    }

    float scale = 5.0f;
    memory_event(Vector3(-target.y / scale, target.x / scale, 0));
}
//void mouseaim(uintptr_t targetmeshs, Vector2 target2d)
//{
//    Vector2 target{};
//    float speedPercent = settings::aimbot.smoothsize;
//    float smoothness = 100.0f - (speedPercent - 1.0f);
//    if (smoothness < 1.0f) smoothness = 1.0f;
//
//    float screen_center_x = static_cast<float>(Width) / 2;
//    float screen_center_y = static_cast<float>(Height) / 2;
//
//    if (target2d.x > screen_center_x) {
//        target.x = -(screen_center_x - target2d.x) / smoothness;
//    }
//    else if (target2d.x < screen_center_x) {
//        target.x = (target2d.x - screen_center_x) / smoothness;
//    }
//
//    if (target2d.y > screen_center_y) {
//        target.y = -(screen_center_y - target2d.y) / smoothness;
//    }
//    else if (target2d.y < screen_center_y) {
//        target.y = (target2d.y - screen_center_y) / smoothness;
//    }
//
//    long move_x = static_cast<long>(std::round(target.x));
//    long move_y = static_cast<long>(std::round(target.y));
//
//    if (!kernel->mouse_move_relative(move_x, move_y))
//    {
//        Sleep(5);
//        kernel->mouse_move_relative(move_x, move_y);
//    }
//}