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


// ============================================================
//  worm shadow :: cs2 single-file cheat
//  build: MSVC x64 -> dll
// ============================================================
#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"
#pragma comment(lib, "minhook/lib/libMinHook.x64.lib")

// ============================================================
//  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){
    int32_t r = *(int32_t*)(a+pos);
    return a + len + r;
}

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(){
        dwEntityList = mem::Rel(mem::Pattern("client.dll",
            "48 8B 0D ?? ?? ?? ?? 48 89 7C 24"), 3, 7);
        dwLocalController = mem::Rel(mem::Pattern("client.dll",
            "48 8B 05 ?? ?? ?? ?? 41 89 BE"), 3, 7);
        dwLocalPawn = mem::Rel(mem::Pattern("client.dll",
            "48 8B 0D ?? ?? ?? ?? 48 8B 01 48 8B 40 38"), 3, 7);
        dwViewMatrix = mem::Rel(mem::Pattern("client.dll",
            "48 8D 0D ?? ?? ?? ?? 48 C1 E0 06"), 3, 7);
        fnTraceShape = mem::Rel(mem::Pattern("client.dll",
            "E8 ?? ?? ?? ?? 48 8B 4D ?? 48 85 C9"), 1, 5);
        fnCreateMove = mem::Pattern("client.dll",
            "48 8B C4 4C 89 48 18 55 56 41 55");
    }
}

// ============================================================
//  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 {
        auto sn = mem::Read<uintptr_t>(ptr+0x328);
        return mem::Read<Vec3>(sn+0xC8);
    }
    Vec3  eye() const {
        auto o = origin();
        float e = mem::Read<float>(ptr+0x14D0);
        return {o.x,o.y,o.z+e};
    }
    uintptr_t bones()const {
        auto sn = mem::Read<uintptr_t>(ptr+0x328);
        return mem::Read<uintptr_t>(sn+0x160+0x80);
    }
    Vec3 bone(int i)const {
        auto b = bones(); if(!b) return {};
        struct B{float x,y,z,w;};
        B v = mem::Read<B>(b+i*32);
        return {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 {};
        auto list = mem::Read<uintptr_t>(offs::dwEntityList);
        if(!list) return {};
        auto e = mem::Read<uintptr_t>(list+0x10+8*(h>>9));
        if(!e) return {};
        return { mem::Read<uintptr_t>(e+8*(h&0x1FF)) };
    }
    std::string name() const {
        const char* n = (const char*)(ptr+0x618);
        __try { return std::string(n); }
        __except(EXCEPTION_EXECUTE_HANDLER){ return "?"; }
    }
    int team() const { return mem::Read<int>(ptr+0x3E4); }
};

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

// ============================================================
//  trace (vis)
// ============================================================
struct CGameTrace { uintptr_t surface; uintptr_t hitEnt; char pad[0x40]; float fraction; };

static bool Visible(const Vec3& a, const Vec3& b, uintptr_t skip){
    if(!offs::fnTraceShape) return false;
    struct F { char p[0x20]; uintptr_t skip; } f{};
    f.skip = skip;
    CGameTrace tr{};
    auto fn = (bool(__fastcall*)(void*,Vec3*,Vec3*,void*,CGameTrace*))offs::fnTraceShape;
    __try { fn(nullptr,(Vec3*)&a,(Vec3*)&b,&f,&tr); }
    __except(EXCEPTION_EXECUTE_HANDLER){ return false; }
    return tr.fraction > 0.97f;
}

// ============================================================
//  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;
    auto vmAddr = mem::Read<uintptr_t>(offs::dwViewMatrix);
    Matrix4x4 vm = mem::Read<Matrix4x4>(vmAddr);
    auto io = ImGui::GetIO();
    int sw=(int)io.DisplaySize.x, sh=(int)io.DisplaySize.y;
    auto dl = ImGui::GetBackgroundDrawList();

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

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

        Vec3 o=p.origin(), 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, bw=bh*0.5f;
        float bx=shh.x-bw*0.5f, by=shh.y;
        ImU32 c=Col(cfg.col);

        if(cfg.box) dl->AddRect({bx,by},{bx+bw,by+bh},c,0,0,cfg.thick);
        if(cfg.hp){
            float f=p.hp()/100.f;
            dl->AddRectFilled({bx-6,by+bh*(1-f)},{bx-2,by+bh},
                ImGui::GetColorU32(ImVec4(1-f,f,0.1f,1)));
        }
        if(cfg.name) dl->AddText({bx,by-16},c,ctrl.name().c_str());
        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(auto& pr:b){
                Vec2 a,c2;
                if(WorldToScreen(p.bone(pr[0]),a,vm,sw,sh) &&
                   WorldToScreen(p.bone(pr[1]),c2,vm,sw,sh))
                    dl->AddLine({a.x,a.y},{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({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;

    auto 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){
        auto ctrl = GetPlayer(i);
        if(!ctrl.ok()) continue;
        auto 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;
        if(cfg.aimVisOnly && !Visible(eye,bone,lp)) continue;

        Vec3 a = CalcAngle(eye,bone);
        float dp = Norm(a.x-cur.x), 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::Checkbox("visible only",&cfg.aimVisOnly);
            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(); }
}

static LRESULT CALLBACK WndProc(HWND h,UINT m,WPARAM w,LPARAM l){
    if(m==WM_KEYDOWN && w==VK_INSERT) cfg.menu=!cfg.menu;
    if(cfg.menu){
        ImGui_ImplWin32_WndProcHandler(h,m,w,l);
        if((m>=WM_MOUSEFIRST&&m<=WM_MOUSELAST)||m==WM_MOUSEMOVE) 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();
        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);
    }

    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();

    // dummy swapchain для Present
    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);

    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;
}