Вопрос C++ | ESP | D3D9

Начинающий
Статус
Оффлайн
Регистрация
9 Мар 2021
Сообщения
131
Реакции[?]
11
Поинты[?]
6K
Форумчане, кто знает в чем проблема фриза игры(не отвисает) и должны ли вообще так выглядеть двухмерные координаты(headScreenPos и feetScreenPos)


1728260576612.png

1728260653958.png

dynamicEax - это адрес-структура игрока/врага/энтити(меняется постоянно)
Например 7E74FB14
1728260715893.png


cheat.cpp:
void ESP() {
    while (true) {
        if (dynamicEax == oldDynamicEax) {
            Sleep(10);
            continue;
        }

        oldDynamicEax = dynamicEax;
        Entity* entity = (Entity*)dynamicEax;
        Vector3 coords = entity->pos;

        if ((coords.x < 2 && coords.x > -2) &&
            (coords.y < 2 && coords.y > -2) &&
            (coords.z < 2 && coords.z > -2) ||
            (coords.x > 25000 || coords.x < -25000) ||
            (coords.y > 25000 || coords.y < -25000) ||
            (coords.z > 25000 || coords.z < -25000))
        {
            Sleep(10);
            continue;
        }

        vec3 headPos = { coords.x, coords.y, coords.z };
        std::cout << "headPos = " << headPos << std::endl;
        vec3 feetPos = { coords.x, coords.y - 1.149f, coords.z };
        std::cout << "feetPos = " << feetPos << std::endl;

        vec3 headScreenPos = WorldToScreen(headPos);
        std::cout << "headScreenPos = " << headScreenPos << std::endl;
        vec3 feetScreenPos = WorldToScreen(feetPos);
        std::cout << "feetScreenPos = " << feetScreenPos << std::endl;

        float height = abs(headScreenPos.y - feetScreenPos.y);
        float width = height / 4;

        ImVec2 topLeft = ImVec2(headScreenPos.x - width, headScreenPos.y);
        ImVec2 topRight = ImVec2(headScreenPos.x + width, headScreenPos.y);

        ImVec2 bottomRight = ImVec2(feetScreenPos.x + width, feetScreenPos.y);
        ImVec2 bottomLeft = ImVec2(feetScreenPos.x - width, feetScreenPos.y);

        ImColor teamColor = ImColor(125, 125, 125, 125);
        ImGui_ImplDX9_NewFrame();
        ImGui_ImplWin32_NewFrame();
        ImGui::NewFrame();
        ImGui::GetOverlayDrawList()->AddQuad(topLeft, bottomLeft, bottomRight, topRight, teamColor, 1.0f);
        ImGui::Render();
        ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());

        Sleep(10);
    }
}

entity.h:
#pragma once
#include "includes.h"
#include "geom.h"
class Entity
{
public:
    char pad_00[48];
    Vector3 pos;
};

geom.h:
#pragma once
#ifndef GEOM_H
#define GEOM_H

#include <math.h>
#include <string>
constexpr auto PI = 3.1415927f;

extern float* viewMatrix;

class Vector3
{
public:

    float x;
    float y;
    float z;

    Vector3() : x(0.0f), y(0.0f), z(0.0f) {}
    Vector3(const float x, const float y, const float z) : x(x), y(y), z(z) {}
    Vector3 operator + (const Vector3& rhs) const { return Vector3(x + rhs.x, y + rhs.y, z + rhs.z); }
    Vector3 operator - (const Vector3& rhs) const { return Vector3(x - rhs.x, y - rhs.y, z - rhs.z); }
    Vector3 operator * (const float& rhs) const { return Vector3(x * rhs, y * rhs, z * rhs); }
    Vector3 operator / (const float& rhs) const { return Vector3(x / rhs, y / rhs, z / rhs); }
    Vector3& operator += (const Vector3& rhs) { return *this = *this + rhs; }
    Vector3& operator += (const float rhs) { return *this = *this + Vector3(rhs, rhs, rhs); }
    Vector3& operator -= (const Vector3& rhs) { return *this = *this - rhs; }
    Vector3& operator *= (const float& rhs) { return *this = *this * rhs; }
    Vector3& operator /= (const float& rhs) { return *this = *this / rhs; }
    float Length() const { return sqrtf(x * x + y * y + z * z); } //AKA Magnitude
    Vector3 Normalize() const { return *this * (1 / Length()); } // 1/ Length()
    float Distance(const Vector3& rhs) const { return (*this - rhs).Length(); }
    Vector3& abs() { x = fabs(x); y = fabs(y); z = fabs(z); return *this; }
    Vector3 NormalizeAngle(); // Wraps around x from 0-360 and y from -90 to 90
    void NormalizeAngle(Vector3& angle); // Wraps around x from 0-360 and y from -90 to 90

    std::string ToString();

    friend std::ostream& operator<<(std::ostream& os, const Vector3& vec)
    {
        os << "(" << vec.x << ", " << vec.y << ", " << vec.z << ")";
        return os;
    }

};

struct Vec4
{
    float x;
    float y;
    float z;
    float w;
};

using Vec3 = Vector3;
using vec3 = Vector3;
using Vec = Vector3;
using vec = Vector3;

bool WorldToScreen(vec3 pos, vec3& screen, float matrix[16], int windowWidth, int windowHeight);
Vec3 WorldToScreen(Vec3& pos, float matrix[16], int windowWidth, int windowHeight);
Vec3 WorldToScreen(Vec3& pos);
Vec3 CalcAngle(Vec3& origin, Vec3& target);


Vec3 DegreesToRadians(Vec3& vec);
float DegreesToRadians(float num);
Vec3 RadiansToDegrees(const Vec3& vec);
float RadiansToDegrees(float num);

#endif // GEOM_H

geom.cpp:
#pragma once
#include "includes.h"
#include "geom.h"


const int windowWidth = 1920;
const int windowHeight = 1080;
// Calculates clip cordinates based on model view projection matrix of a game, and then converts clip cords into screen space
bool WorldToScreen(vec3 pos, vec3& screen, float matrix[16], int windowWidth, int windowHeight)
{
    Vec4 clipCoords;

    clipCoords.x = pos.x * matrix[0] + pos.y * matrix[4] + pos.z * matrix[8] + matrix[12];
    clipCoords.y = pos.x * matrix[1] + pos.y * matrix[5] + pos.z * matrix[9] + matrix[13];
    clipCoords.z = pos.x * matrix[2] + pos.y * matrix[6] + pos.z * matrix[10] + matrix[14];
    clipCoords.w = pos.x * matrix[3] + pos.y * matrix[7] + pos.z * matrix[11] + matrix[15];

    if (clipCoords.w < 0.1f)
    {
        return false;
    }

    vec3 NDC{ clipCoords.x / clipCoords.w, clipCoords.y / clipCoords.w, clipCoords.z / clipCoords.w };


    screen.x = (windowWidth / 2.0 * NDC.x) + (NDC.x + windowWidth / 2.0);
    screen.y = -(windowHeight / 2.0 * NDC.y) + (NDC.y + windowHeight / 2.0);

    return true;
}

Vec3 WorldToScreen(Vec3& pos, float matrix[16], int windowWidth, int windowHeight)
{
    Vec4 clipCoords;

    clipCoords.x = pos.x * matrix[0] + pos.y * matrix[4] + pos.z * matrix[8] + matrix[12];
    clipCoords.y = pos.x * matrix[1] + pos.y * matrix[5] + pos.z * matrix[9] + matrix[13];
    clipCoords.z = pos.x * matrix[2] + pos.y * matrix[6] + pos.z * matrix[10] + matrix[14];
    clipCoords.w = pos.x * matrix[3] + pos.y * matrix[7] + pos.z * matrix[11] + matrix[15];

    if (clipCoords.w < 0.1f)
    {
        return Vec3{ 0.0f, 0.0f, 0.0f };
    }

    Vec3 NDC{ clipCoords.x / clipCoords.w, clipCoords.y / clipCoords.w, clipCoords.z / clipCoords.w };
}


Vec3 WorldToScreen(Vec3 &pos)
{
    vec3 screen;
    HMODULE moduleESP = GetModuleHandleA("prbf2.exe");
    uintptr_t baseAddressESP = reinterpret_cast<uintptr_t>(moduleESP);
    std::cout << std::hex << "vec3 WorldToScreen baseAddressESP Address: " << baseAddressESP << std::endl;
    uintptr_t viewMatrixAddressCalc1 = baseAddressESP + 0x005A557C;
    std::cout << std::hex << "viewMatrixAddressCalc1 Address: " << viewMatrixAddressCalc1 << std::endl;
    uintptr_t viewMatrixAddressCalc2 = [I]reinterpret_cast<uintptr_t[/I]>(viewMatrixAddressCalc1) + 0xF8;
    std::cout << std::hex << "viewMatrixAddressCalc2 Address: " << viewMatrixAddressCalc2 << std::endl;
    uintptr_t viewMatrixAddress = [I]reinterpret_cast<uintptr_t[/I]>(viewMatrixAddressCalc2) + 0x3C;
    std::cout << std::hex << "viewMatrixAddress Address: " << viewMatrixAddress << std::endl;
    float* viewMatrix = reinterpret_cast<float*>(viewMatrixAddress);
    std::cout << std::hex << "ViewMatrix Address: " << viewMatrixAddress << std::endl;
    if (WorldToScreen(pos, screen, viewMatrix, windowWidth, windowHeight))
        return screen;
    return vec3(0, 0, 0);
}


// Gets angle of a ray from origin to target
Vec3 CalcAngle(Vec3& origin, Vec3& target)
{
    Vec3 results{ 0.0f, 0.0f, 0.0f };
    results.x = RadiansToDegrees(-atan2f(target.x - origin.x, target.y - origin.y));
    if (results.x <= 0.0f)
    {
        results.x += 360.0f;
    }

    results.y = RadiansToDegrees(asinf((target.z - origin.z) / origin.Distance(target)));
    return results;
}

Vec3 DegreesToRadians(Vec3& vec)
{
    // Wasteful, but function is never used and I trust my compiler to inline these
    return Vec3{ DegreesToRadians(vec.x), DegreesToRadians(vec.y), DegreesToRadians(vec.z) };
}

float DegreesToRadians(float num)
{
    return num / 180.0f * PI;
}

Vec3 RadiansToDegrees(const Vec3& vec)
{
    return Vec3{ vec.x / PI * 180.0f, vec.y / PI * 180.0f, vec.z / PI * 180.0f };
}

float RadiansToDegrees(float num)
{
    return num / PI * 180.0f;
}

//Vector3 Vector3::NormalizeAngle()
//{
//    if (x > 360)
//        x -= 360;
//    if (x < 0)
//        x += 360;
//    if (y > 90)
//        y -= 90;
//    if (y < -90)
//        y += 90;
//}
void Vector3::NormalizeAngle(Vector3& angle) {
    if (angle.x > 360)
        angle.x -= 360;
    if (angle.x < 0)
        angle.x += 360;
    if (angle.y > 90)
        angle.y -= 90;
    if (angle.y < -90)
        angle.y += 90;
}
std::string Vector3::ToString()
{
    return std::to_string(x) + " " + std::to_string(y) + " " + std::to_string(z);
}
 
Последнее редактирование:
Сверху Снизу