Загрузка данных


#include <windows.h>
#include <d3d11.h>
#include <dxgi.h>
#include <string>
#include <vector>
#include <cmath>
#include <cstdint>
#include <cstdio>

#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")

#include "imgui/imgui.h"
#include "imgui/backends/imgui_impl_dx11.h"
#include "imgui/backends/imgui_impl_win32.h"
#include "minhook/include/MinHook.h"

// ============================================================
// math
// ============================================================
struct Vec2 { float x, y; };
struct Vec3 {
    float x, y, z;
    Vec3 operator+(const Vec3& o) const { return { x + o.x, y + o.y, z + o.z }; }
    Vec3 operator-(const Vec3& o) const { return { x - o.x, y - o.y, z - o.z }; }
    Vec3 operator*(float s)      const { return { x * s, y * s, z * s }; }
    float Dot(const Vec3& o)     const { return x * o.x + y * o.y + z * o.z; }
    float Length()               const { return std::sqrt(x * x + y * y + z * z); }
    Vec3 Normalized()            const { float l = Length(); return l > 1e-4f ? Vec3{ x / l, y / l, z / l } : Vec3{ 0,0,0 }; }
};
struct Matrix4x4 { float m[4][4]; };

static float Deg2Rad(float d) { return d * 3.14159265f / 180.f; }
static float Rad2Deg(float r) { return r * 180.f / 3.14159265f; }

static bool WorldToScreen(const Vec3& w, Vec2& out, const Matrix4x4& vm, int sw, int sh) {
    float ww = vm.m[3][0] * w.x + vm.m[3][1] * w.y + vm.m[3][2] * w.z + vm.m[3][3];
    if (ww < 0.01f) return false;
    float xx = vm.m[0][0] * w.x + vm.m[0][1] * w.y + vm.m[0][2] * w.z + vm.m[0][3];
    float yy = vm.m[1][0] * w.x + vm.m[1][1] * w.y + vm.m[1][2] * w.z + vm.m[1][3];
    out.x = (sw * 0.5f) + (xx / ww) * (sw * 0.5f);
    out.y = (sh * 0.5f) - (yy / ww) * (sh * 0.5f);
    return true;
}

// ============================================================
// memory utils
// ============================================================
namespace mem {
    inline uintptr_t Base(const char* n) { return (uintptr_t)GetModuleHandleA(n); }

    inline size_t Size(const char* n) {
        auto b = Base(n); if (!b) return 0;
        auto dos = (IMAGE_DOS_HEADER*)b;
        auto nt = (IMAGE_NT_HEADERS*)(b + dos->e_lfanew);
        return nt->OptionalHeader.SizeOfImage;
    }

    inline uintptr_t Pattern(const char* mod, const char* pat) {
        auto base = Base(mod), sz = Size(mod);
        if (!base || !sz) return 0;
        std::vector<int> bytes;
        for (const char* p = pat; *p; ) {
            if (*p == ' ') { ++p; continue; }
            if (*p == '?') { bytes.push_back(-1); ++p; if (*p == '?')++p; }
            else { bytes.push_back((int)strtol(std::string(p, 2).c_str(), nullptr, 16)); p += 2; }
        }
        auto d = (uint8_t*)base;
        for (size_t i = 0; i + bytes.size() < sz; ++i) {
            bool f = true;
            for (size_t j = 0; j < bytes.size(); ++j)
                if (bytes[j] != -1 && d[i + j] != (uint8_t)bytes[j]) { f = false; break; }
            if (f) return base + i;
        }
        return 0;
    }

    inline uintptr_t Rel(uintptr_t a, int pos, int len) {
        if (!a) return 0;
        __try {
            int32_t r = *(int32_t*)(a + pos);
            return a + len + r;
        }
        __except (EXCEPTION_EXECUTE_HANDLER) { return 0; }
    }

    template<typename T> inline T Read(uintptr_t a) {
        if (!a) return T{};
        __try { return *(T*)a; }
        __except (EXCEPTION_EXECUTE_HANDLER) { return T{}; }
    }

    template<typename T> inline void Write(uintptr_t a, T v) {
        if (!a) return;
        __try { *(T*)a = v; }
        __except (EXCEPTION_EXECUTE_HANDLER) {}
    }
}

// ============================================================
// offsets (scan)
// ============================================================
namespace offs {
    inline uintptr_t dwEntityList = 0;
    inline uintptr_t dwLocalController = 0;
    inline uintptr_t dwLocalPawn = 0;
    inline uintptr_t dwViewMatrix = 0;
    inline uintptr_t fnCreateMove = 0;
    inline uintptr_t fnTraceShape = 0;

    inline void Init() {
        auto p1 = mem::Pattern("client.dll", "48 8B 0D ?? ?? ?? ?? 48 89 7C 24");
        if (p1) dwEntityList = mem::Rel(p1, 3, 7);

        auto p2 = mem::Pattern("client.dll", "48 8B 05 ?? ?? ?? ?? 41 89 BE");
        if (p2) dwLocalController = mem::Rel(p2, 3, 7);

        auto p3 = mem::Pattern("client.dll", "48 8B 0D ?? ?? ?? ?? 48 8B 01 48 8B 40 38");
        if (p3) dwLocalPawn = mem::Rel(p3, 3, 7);

        auto p4 = mem::Pattern("client.dll", "48 8D 0D ?? ?? ?? ?? 48 C1 E0 06");
        if (p4) dwViewMatrix = mem::Rel(p4, 3, 7);

        auto p5 = mem::Pattern("client.dll", "E8 ?? ?? ?? ?? 48 8B 4D ?? 48 85 C9");
        if (p5) fnTraceShape = mem::Rel(p5, 1, 5);

        auto p6 = mem::Pattern("client.dll", "48 8B C4 4C 89 48 18 55 56 41 55");
        if (p6) fnCreateMove = p6;
    }
}

// ============================================================
// entity
// ============================================================
struct Pawn {
    uintptr_t ptr = 0;
    bool ok() const { return ptr != 0; }
    int hp() const { return mem::Read<int>(ptr + 0x344); }
    int team() const { return mem::Read<int>(ptr + 0x3C8); }
    bool alive() const { return hp() > 0; }

    Vec3 origin() const {
        uintptr_t sn = mem::Read<uintptr_t>(ptr + 0x328);
        return mem::Read<Vec3>(sn + 0xC8);
    }
    Vec3 eye() const {
        Vec3 o = origin();
        float e = mem::Read<float>(ptr + 0x14D0);
        return Vec3(o.x, o.y, o.z + e);
    }
    uintptr_t bones() const {
        uintptr_t sn = mem::Read<uintptr_t>(ptr + 0x328);
        return mem::Read<uintptr_t>(sn + 0x160 + 0x80);
    }
    Vec3 bone(int i) const {
        uintptr_t b = bones();
        if (!b) return Vec3(0, 0, 0);
        struct B { float x, y, z, w; };
        B v = mem::Read<B>(b + i * 32);
        return Vec3(v.x, v.y, v.z);
    }
    bool spotted() const {
        return mem::Read<bool>(ptr + 0x1C38);
    }
};

struct Controller {
    uintptr_t ptr = 0;
    bool ok() const { return ptr != 0; }

    Pawn pawn() const {
        uintptr_t h = mem::Read<uintptr_t>(ptr + 0x7D8);
        if (!h) return Pawn{ 0 };
        uintptr_t list = mem::Read<uintptr_t>(offs::dwEntityList);
        if (!list) return Pawn{ 0 };
        uintptr_t e = mem::Read<uintptr_t>(list + 0x10 + 8 * (h >> 9));
        if (!e) return Pawn{ 0 };
        uintptr_t result = mem::Read<uintptr_t>(e + 8 * (h & 0x1FF));
        return Pawn{ result };
    }
    const char* name() const {
        const char* n = (const char*)(ptr + 0x618);
        __try { if (n) return n; }
        __except (EXCEPTION_EXECUTE_HANDLER) {}
        return "?";
    }
    int team() const { return mem::Read<int>(ptr + 0x3E4); }
};

static Controller GetPlayer(int i) {
    uintptr_t list = mem::Read<uintptr_t>(offs::dwEntityList);
    if (!list) return Controller{ 0 };
    uintptr_t e = mem::Read<uintptr_t>(list + 0x10 + 8 * (i >> 9));
    if (!e) return Controller{ 0 };
    uintptr_t result = mem::Read<uintptr_t>(e + 8 * (i & 0x1FF));
    return Controller{ result };
}

// ============================================================
// config
// ============================================================
struct Config {
    bool  espEn = true, box = true, skel = true, hp = true, name = true, dist = true, visOnly = false;
    float col[4] = { 0.15f, 0.85f, 1.f, 1.f };
    float thick = 1.5f;

    bool  aimEn = false, aimOnKey = true;
    int   aimKey = VK_XBUTTON2;
    float aimFov = 12.f, aimSmooth = 4.f;
    int   aimBone = 6;
    bool  aimVisOnly = true;

    bool  spinEn = false;
    float spinSpeed = 15.f;

    bool  menu = false;
} cfg;

// ============================================================
// esp
// ============================================================
static ImU32 Col(const float c[4]) { return ImGui::GetColorU32(ImVec4(c[0], c[1], c[2], c[3])); }

static void DrawESP() {
    if (!cfg.espEn) return;
    uintptr_t vmAddr = mem::Read<uintptr_t>(offs::dwViewMatrix);
    Matrix4x4 vm = mem::Read<Matrix4x4>(vmAddr);
    ImGuiIO& io = ImGui::GetIO();
    int sw = (int)io.DisplaySize.x;
    int sh = (int)io.DisplaySize.y;
    ImDrawList* dl = ImGui::GetBackgroundDrawList();

    uintptr_t lp = mem::Read<uintptr_t>(offs::dwLocalPawn);
    if (!lp) return;
    Pawn me(lp);
    int myTeam = me.team();

    for (int i = 1; i <= 64; ++i) {
        Controller ctrl = GetPlayer(i);
        if (!ctrl.ok()) continue;
        Pawn p = ctrl.pawn();
        if (!p.ok() || !p.alive()) continue;
        if (p.team() == myTeam) continue;
        if (cfg.visOnly && !p.spotted()) continue;

        Vec3 o = p.origin();
        Vec3 h = p.bone(6);
        Vec2 so, shh;
        if (!WorldToScreen(o, so, vm, sw, sh)) continue;
        if (!WorldToScreen(h, shh, vm, sw, sh)) continue;

        float bh = so.y - shh.y;
        float bw = bh * 0.5f;
        float bx = shh.x - bw * 0.5f;
        float by = shh.y;
        ImU32 c = Col(cfg.col);

        if (cfg.box) dl->AddRect(ImVec2(bx, by), ImVec2(bx + bw, by + bh), c, 0, 0, cfg.thick);
        if (cfg.hp) {
            float f = p.hp() / 100.f;
            dl->AddRectFilled(ImVec2(bx - 6, by + bh * (1 - f)), ImVec2(bx - 2, by + bh), ImGui::GetColorU32(ImVec4(1 - f, f, 0.1f, 1)));
        }
        if (cfg.name) dl->AddText(ImVec2(bx, by - 16), c, ctrl.name());
        if (cfg.skel) {
            static const int b[][2] = { {6,5},{5,4},{4,3},{5,7},{7,8},{8,9}, {5,11},{11,12},{12,13},{4,14},{14,15},{15,16}, {4,17},{17,18},{18,19} };
            for (int j = 0; j < 15; ++j) {
                Vec2 a, c2;
                if (WorldToScreen(p.bone(b[j][0]), a, vm, sw, sh) && WorldToScreen(p.bone(b[j][1]), c2, vm, sw, sh)) {
                    dl->AddLine(ImVec2(a.x, a.y), ImVec2(c2.x, c2.y), c, cfg.thick);
                }
            }
        }
        if (cfg.dist) {
            float d = (o - me.origin()).Length() / 100.f;
            char buf[32];
            snprintf(buf, sizeof buf, "[%.0fm]", d);
            dl->AddText(ImVec2(bx, by + bh + 2), c, buf);
        }
    }
}

// ============================================================
// aimbot
// ============================================================
static Vec3 CalcAngle(const Vec3& f, const Vec3& t) {
    Vec3 d = t - f;
    float hyp = std::sqrt(d.x * d.x + d.y * d.y);
    return { Rad2Deg(std::atan2(-d.z, hyp)), Rad2Deg(std::atan2(d.y, d.x)), 0.f };
}
static float Norm(float a) { while (a > 180)a -= 360; while (a < -180)a += 360; return a; }

static void RunAimbot(void* input) {
    if (!cfg.aimEn) return;
    if (cfg.aimOnKey && !(GetAsyncKeyState(cfg.aimKey) & 0x8000)) return;

    uintptr_t lp = mem::Read<uintptr_t>(offs::dwLocalPawn);
    if (!lp) return;
    Pawn me(lp);
    if (!me.alive()) return;

    Vec3 eye = me.eye();
    int myTeam = me.team();
    Vec3 cur = mem::Read<Vec3>((uintptr_t)input + 0x2E0);

    float best = cfg.aimFov;
    Vec3 bestAng;
    bool has = false;

    for (int i = 1; i <= 64; ++i) {
        Controller ctrl = GetPlayer(i);
        if (!ctrl.ok()) continue;
        Pawn p = ctrl.pawn();
        if (!p.ok() || !p.alive()) continue;
        if (p.team() == myTeam) continue;

        Vec3 bone = p.bone(cfg.aimBone);
        if (bone.x == 0 && bone.y == 0 && bone.z == 0) continue;
        
        Vec3 a = CalcAngle(eye, bone);
        float dp = Norm(a.x - cur.x);
        float dy = Norm(a.y - cur.y);
        float f = std::sqrt(dp * dp + dy * dy);
        if (f < best) {
            best = f;
            bestAng = a;
            has = true;
        }
    }
    if (!has) return;

    float step = cfg.aimSmooth > 0.01f ? 1.f / cfg.aimSmooth : 1.f;
    Vec3 out;
    out.x = cur.x + Norm(bestAng.x - cur.x) * step;
    out.y = cur.y + Norm(bestAng.y - cur.y) * step;
    out.z = 0;
    mem::Write<Vec3>((uintptr_t)input + 0x2E0, out);
}

// ============================================================
// spin
// ============================================================
static float g_spin = 0;
static void RunSpin(void* input) {
    if (!cfg.spinEn) return;
    g_spin += cfg.spinSpeed;
    if (g_spin > 360) g_spin -= 360;
    __try {
        Vec3* a = (Vec3*)((uintptr_t)input + 0x2E0);
        a->y = g_spin; a->x = 0;
    } __except (EXCEPTION_EXECUTE_HANDLER) {}
}

// ============================================================
// menu
// ============================================================
static void DrawMenu() {
    if (!cfg.menu) return;
    ImGui::SetNextWindowSize({ 480, 400 }, ImGuiCond_FirstUseEver);
    ImGui::Begin("worm shadow :: cs2", nullptr, ImGuiWindowFlags_NoCollapse);
    if (ImGui::BeginTabBar("t")) {
        if (ImGui::BeginTabItem("visuals")) {
            ImGui::Checkbox("enabled", &cfg.espEn);
            ImGui::Checkbox("box", &cfg.box);
            ImGui::Checkbox("skeleton", &cfg.skel);
            ImGui::Checkbox("health", &cfg.hp);
            ImGui::Checkbox("name", &cfg.name);
            ImGui::Checkbox("distance", &cfg.dist);
            ImGui::Checkbox("visible only", &cfg.visOnly);
            ImGui::SliderFloat("thickness", &cfg.thick, 0.5f, 4.f);
            ImGui::ColorEdit4("color", cfg.col);
            ImGui::EndTabItem();
        }
        if (ImGui::BeginTabItem("aim")) {
            ImGui::Checkbox("enabled", &cfg.aimEn);
            ImGui::Checkbox("on key", &cfg.aimOnKey);
            ImGui::SliderFloat("fov", &cfg.aimFov, 1, 90);
            ImGui::SliderFloat("smooth", &cfg.aimSmooth, 0.5f, 20);
            const char* bn[] = { "pelvis","chest","neck","head" };
            int bi = cfg.aimBone <= 3 ? 0 : cfg.aimBone == 4 ? 1 : cfg.aimBone == 5 ? 2 : 3;
            if (ImGui::Combo("bone", &bi, bn, 4)) {
                static const int map[] = { 0,4,5,6 };
                cfg.aimBone = map[bi];
            }
            ImGui::EndTabItem();
        }
        if (ImGui::BeginTabItem("spin")) {
            ImGui::Checkbox("enabled", &cfg.spinEn);
            ImGui::SliderFloat("speed", &cfg.spinSpeed, 1, 60);
            ImGui::EndTabItem();
        }
        ImGui::EndTabBar();
    }
    ImGui::End();
}

// ============================================================
// hooks
// ============================================================
using PresentFn = HRESULT(__stdcall*)(IDXGISwapChain*, UINT, UINT);
using CreateMoveFn = bool(__fastcall*)(void*, void*);
static PresentFn    oPresent = nullptr;
static CreateMoveFn oCreateMove = nullptr;

static ID3D11Device* g_dev = nullptr;
static ID3D11DeviceContext* g_ctx = nullptr;
static ID3D11RenderTargetView* g_rtv = nullptr;
static HWND                    g_hwnd = nullptr;
static WNDPROC                 g_wnd = nullptr;

static void MakeRTV(IDXGISwapChain* sc) {
    ID3D11Texture2D* bb = nullptr;
    sc->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&bb);
    if (bb) { g_dev->CreateRenderTargetView(bb, nullptr, &g_rtv); bb->Release(); }
}

extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

static LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
    if (m == WM_KEYDOWN && w == VK_INSERT) {
        cfg.menu = !cfg.menu;
    }

    ImGui_ImplWin32_WndProcHandler(h, m, w, l);
    
    if (cfg.menu) {
        ImGuiIO& io = ImGui::GetIO();
        if (io.WantCaptureMouse && ((m >= WM_MOUS;EFIRST && m <= WM_MOUSELAST // Р) || m == WM_MOUSEMOVE))
            return true;
        if (io.WantCaptureKeyboard && (m >= WM_KEYFIRST && m <= WM_KEYLAST))
            return true;
    }

    return CallWindowProc(g_wnd, h, m, w, l);
}

static HRESULT __stdcall Present(IDXGISwapChain* sc, UINT s, UINT f) {
    if (!g_dev) {
        sc->GetDevice(__uuidof(ID3D11Device), (void**)&g_dev);
        g_dev->GetImmediateContext(&g_ctx);
        DXGI_SWAP_CHAIN_DESC d; sc->GetDesc(&d);
        g_hwnd = d.OutputWindow;
        MakeRTV(sc);

        ImGui::CreateContext();
        
        // --- СТИЛЬ МЕНЮ ---
        ImGuiStyle& style = ImGui::GetStyle();
        ImGui::StyleColorsDark();
        style.WindowRounding = 6.0f;
        style.FrameRounding = 4.0f;
        style.PopupRounding = 4.0f;
        style.ScrollbarRounding = 4.0f;
        style.GrabRounding = 4.0f;
        style.TabRounding = 4.0f;
        style.WindowPadding = ImVec2(10, 10);
        style.FramePadding = ImVec2(6, 4);
        
        ImVec4* colors = style.Colors;
        colors[ImGuiCol_WindowBg]       = ImVec4(0.08f, 0.08f, 0.10f, 0.95f);
        colors[ImGuiCol_Header]         = ImVec4(0.20f, 0.25f, 0.35f, 1.00f);
        colors[ImGuiCol_HeaderHovered]  = ImVec4(0.30f, 0.35f, 0.45f, 1.00f);
        colors[ImGuiCol_HeaderActive]   = ImVec4(0.15f, 0.20f, 0.30f, 1.00f);
        colors[ImGuiCol_Button]         = ImVec4(0.20f, 0.25f, 0.35f, 1.00f);
        colors[ImGuiCol_ButtonHovered]  = ImVec4(0.30f, 0.35f, 0.45f, 1.00f);
        colors[ImGuiCol_ButtonActive]   = ImVec4(0.15f, 0.20f, 0.30f, 1.00f);
        colors[ImGuiCol_CheckMark]      = ImVec4(0.00f, 0.80f, 1.00f, 1.00f);
        colors[ImGuiCol_SliderGrab]     = ImVec4(0.00f, 0.80f, 1.00f, 1.00f);
        colors[ImGuiCol_SliderGrabActive]= ImVec4(0.00f, 1.00f, 1.00f, 1.00f);
        colors[ImGuiCol_Text]           = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
        // -----------------

        ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
        ImGui_ImplWin32_Init(g_hwnd);
        ImGui_ImplDX11_Init(g_dev, g_ctx);

        g_wnd = (WNDPROC)SetWindowLongPtr(g_hwnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
    }

    ImGui::GetIO().MouseDrawCursor = cfg.menuисуем свой курсор

    DrawESP();

    ImGui_ImplDX11_NewFrame();
    ImGui_ImplWin32_NewFrame();
    ImGui::NewFrame();
    DrawMenu();
    ImGui::Render();
    g_ctx->OMSetRenderTargets(1, &g_rtv, nullptr);
    ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());

    return oPresent(sc, s, f);
}

static bool __fastcall CreateMove(void* in, void* a2) {
    bool r = oCreateMove(in, a2);
    RunSpin(in);
    RunAimbot(in);
    return r;
}

// ============================================================
// init
// ============================================================
static DWORD WINAPI Main(LPVOID) {
    while (!GetModuleHandleA("client.dll")) Sleep(100);
    Sleep(1500);
    offs::Init();
    MH_Initialize();

    WNDCLASSEXA wc{ sizeof wc };
    wc.lpfnWndProc = DefWindowProcA;
    wc.hInstance = GetModuleHandleA(nullptr);
    wc.lpszClassName = "wsc";
    RegisterClassExA(&wc);
    HWND dummy = CreateWindowA("wsc", "", WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, nullptr, nullptr, wc.hInstance, nullptr);

    DXGI_SWAP_CHAIN_DESC sd{};
    sd.BufferCount = 1;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = dummy;
    sd.SampleDesc.Count = 1;
    sd.Windowed = TRUE;
    sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

    IDXGISwapChain* sc = nullptr; 
    ID3D11Device* dv = nullptr; 
    ID3D11DeviceContext* cx = nullptr;
    D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, &sd, &sc, &dv, nullptr, &cx);

    if (!sc) return 0;

    void** vt = *(void***)sc;
    MH_CreateHook(vt[8], &Present, (void**)&oPresent);
    MH_EnableHook(vt[8]);
    
    sc->Release(); dv->Release(); cx->Release();
    DestroyWindow(dummy); UnregisterClassA("wsc", wc.hInstance);

    if (offs::fnCreateMove) {
        MH_CreateHook((void*)offs::fnCreateMove, &CreateMove, (void**)&oCreateMove);
        MH_EnableHook((void*)offs::fnCreateMove);
    }

    return 0;
}

BOOL APIENTRY DllMain(HMODULE, DWORD r, LPVOID) {
    if (r == DLL_PROCESS_ATTACH) {
        DisableThreadLibraryCalls(GetModuleHandleA(nullptr));
        CreateThread(nullptr, 0, Main, nullptr, 0, nullptr);
    }
    return TRUE;
}