Исходник Информация Гайд Пишем ВХ на cs #Урок

Статус
В этой теме нельзя размещать новые ответы.

gresearch

Новичок
Автор темы
9
19
Для начала ознакомьтесь с текстом для копирования, который будет вам полезен в любых(оффлайн) играх сделанных на DirectX
Main.cpp:
C++:
#include "Header.h"
#include "detours.h"
#include "cDraw.h"
#include "Visual.h"


typedef HRESULT(WINAPI* oEndScene)(LPDIRECT3DDEVICE9 pDevice);
oEndScene pEndScene = NULL;
//
HMODULE hModule = 0;/// Зачем? в главной функции написано!
bool Create;
bool dsa = false;
cDraw Draw;
HRESULT APIENTRY myEndScene(LPDIRECT3DDEVICE9 pDevice)
{
    if (!Create)
    {
      
        D3DXCreateLine(pDevice, &Draw.pLine);
        Draw.InitFont((LPSTR) "verdana", 13, FW_BOLD, pDevice);
        Create = true;
    }
    Draw.draw(VK_HOME, pDevice);
    if (false)
    {
        dsa = true;
    }
    if (dsa == false)
    {
        return pEndScene(pDevice);
    }


}




#include "DirectHoock.h"
BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved)///| Главная функция в которой помимо вызова
{                                                                    ///| патоков сделаем запись хендла модуля в глобал
    hModule = hDll;                                                    ///| переменную для последующего выгружения dll
    DisableThreadLibraryCalls(hDll);

    if (dwReason == DLL_PROCESS_ATTACH)
    {
        hModule = hDll;
        Start_Therad(LoopFunction);
      
    }
    return TRUE;
}
DirectHoock.h:
C++:
#pragma once
//#include "Header.h"

#pragma region D3D9_Interface_Hook

LPD3DXFONT pFont;
bool Font = true;

bool hooked = false;
#define HOOK(func,addy) p##func = (o##func)DetourFunction((PBYTE)addy,(PBYTE)my##func)
#define UNHOOK(func,addy) p##func = (o##func)DetourFunction((PBYTE)addy,(PBYTE)p##func)
LPDIRECT3DDEVICE9 nm_pD3Ddev;
PBYTE HookVTable(PDWORD* dwVTable, PBYTE dwHook, INT Index)
{
    DWORD dwOld = 0;
    VirtualProtect((void*)((*dwVTable) + (Index * 4)), 4, PAGE_EXECUTE_READWRITE, &dwOld);
    PBYTE pOrig = ((PBYTE)(*dwVTable)[Index]);
    (*dwVTable)[Index] = (DWORD)dwHook;
    VirtualProtect((void*)((*dwVTable) + (Index * 4)), 4, dwOld, &dwOld);
    return pOrig;
}
LRESULT CALLBACK MsgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return DefWindowProc(hwnd, uMsg, wParam, lParam); }
void DX_Init(DWORD* table)
{
    WNDCLASSEXA wc = { sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandleA(NULL),NULL,NULL,NULL,NULL,"DX",NULL };
    RegisterClassExA(&wc);
    HWND hWnd = CreateWindowA("DX", NULL, WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL);
    LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION);
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    LPDIRECT3DDEVICE9 pd3dDevice;
    pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice);
    DWORD* pVTable = (DWORD*)pd3dDevice;
    pVTable = (DWORD*)pVTable[0];
    table[0] = pVTable[42];
    DestroyWindow(hWnd);
}

DWORD WINAPI VMT_Patching(LPVOID  Param)
{
    while (1)
    {
        Sleep(100);
        HookVTable((PDWORD*)nm_pD3Ddev, (PBYTE)myEndScene, 42);
    }
    return 1;
}

void LoopFunction()
{
    if (hooked == false)
    {
        DWORD VTable[3] = { 0 };
        while (GetModuleHandleA("d3d9.dll") == NULL)
        {
            Sleep(250);
        }
        DX_Init(VTable);
        HOOK(EndScene, VTable[0]);
        while (!nm_pD3Ddev)
        {
            Sleep(50);
        }
        UNHOOK(EndScene, VTable[0]);
        *(PDWORD)&pEndScene = VTable[0];
        CreateThread(NULL, 0, &VMT_Patching, NULL, 0, NULL); //Create hooking thread
        hooked = true;
    }
}
#pragma endregion D3D9_Interface_Hook
detours.h:
C++:
#pragma once
#ifndef _DETOURS_H_
#define _DETOURS_H_

#pragma comment(lib, "detours")

//////////////////////////////////////////////////////////////////////////////
//
#ifndef GUID_DEFINED
#define GUID_DEFINED
typedef struct  _GUID
{
    DWORD Data1;
    WORD Data2;
    WORD Data3;
    BYTE Data4[8];
} GUID;
#endif // !GUID_DEFINED

#if defined(__cplusplus)
#ifndef _REFGUID_DEFINED
#define _REFGUID_DEFINED
#define REFGUID             const GUID &
#endif // !_REFGUID_DEFINED
#else // !__cplusplus
#ifndef _REFGUID_DEFINED
#define _REFGUID_DEFINED
#define REFGUID             const GUID * const
#endif // !_REFGUID_DEFINED
#endif // !__cplusplus
//
//////////////////////////////////////////////////////////////////////////////

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

    /////////////////////////////////////////////////// Instruction Target Macros.
    //
#define DETOUR_INSTRUCTION_TARGET_NONE          ((PBYTE)0)
#define DETOUR_INSTRUCTION_TARGET_DYNAMIC       ((PBYTE)~0ul)

/////////////////////////////////////////////////////////// Trampoline Macros.
//
// DETOUR_TRAMPOLINE(trampoline_prototype, target_name)
//
// The naked trampoline must be at least DETOUR_TRAMPOLINE_SIZE bytes.
//
#define DETOUR_TRAMPOLINE_SIZE          32
#define DETOUR_SECTION_HEADER_SIGNATURE 0x00727444   // "Dtr\0"

#define DETOUR_TRAMPOLINE(trampoline,target) \
static PVOID __fastcall _Detours_GetVA_##target(VOID) \
{ \
    return ⌖ \
} \
\
__declspec(naked) trampoline \
{ \
    __asm { nop };\
    __asm { nop };\
    __asm { call _Detours_GetVA_##target };\
    __asm { jmp eax };\
    __asm { ret };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
}

#define DETOUR_TRAMPOLINE_EMPTY(trampoline) \
__declspec(naked) trampoline \
{ \
    __asm { nop };\
    __asm { nop };\
    __asm { xor eax, eax };\
    __asm { mov eax, [eax] };\
    __asm { ret };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
    __asm { nop };\
}

/////////////////////////////////////////////////////////// Binary Structures.
//
#pragma pack(push, 8)
    typedef struct _DETOUR_SECTION_HEADER
    {
        DWORD       cbHeaderSize;
        DWORD       nSignature;
        DWORD       nDataOffset;
        DWORD       cbDataSize;

        DWORD       nOriginalImportVirtualAddress;
        DWORD       nOriginalImportSize;
        DWORD       nOriginalBoundImportVirtualAddress;
        DWORD       nOriginalBoundImportSize;

        DWORD       nOriginalIatVirtualAddress;
        DWORD       nOriginalIatSize;
        DWORD       nOriginalSizeOfImage;
        DWORD       nReserve;
    } DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER;

    typedef struct _DETOUR_SECTION_RECORD
    {
        DWORD       cbBytes;
        DWORD       nReserved;
        GUID        guid;
    } DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD;
#pragma pack(pop)

#define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \
{ \
      sizeof(DETOUR_SECTION_HEADER),\
      DETOUR_SECTION_HEADER_SIGNATURE,\
      sizeof(DETOUR_SECTION_HEADER),\
      (cbSectionSize),\
      \
      0,\
      0,\
      0,\
      0,\
      \
      0,\
      0,\
      0,\
      0,\
}

    ///////////////////////////////////////////////////////////// Binary Typedefs.
    //
    typedef BOOL(CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)(PVOID pContext,
        PCHAR pszFile,
        PCHAR *ppszOutFile);
    typedef BOOL(CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)(PVOID pContext,
        PCHAR pszOrigFile,
        PCHAR pszFile,
        PCHAR *ppszOutFile);
    typedef BOOL(CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)(PVOID pContext,
        DWORD nOrdinal,
        PCHAR pszOrigSymbol,
        PCHAR pszSymbol,
        PCHAR *ppszOutSymbol);
    typedef BOOL(CALLBACK *PF_DETOUR_BINARY_FINAL_CALLBACK)(PVOID pContext);
    typedef BOOL(CALLBACK *PF_DETOUR_BINARY_EXPORT_CALLBACK)(PVOID pContext,
        DWORD nOrdinal,
        PCHAR pszName,
        PBYTE pbCode);

    typedef VOID * PDETOUR_BINARY;
    typedef VOID * PDETOUR_LOADED_BINARY;

    //////////////////////////////////////////////////////// Trampoline Functions.
    //
    PBYTE WINAPI DetourFunction(PBYTE pbTargetFunction,
        PBYTE pbDetourFunction);

    BOOL WINAPI DetourFunctionWithEmptyTrampoline(PBYTE pbTrampoline,
        PBYTE pbTarget,
        PBYTE pbDetour);

    BOOL WINAPI DetourFunctionWithEmptyTrampolineEx(PBYTE pbTrampoline,
        PBYTE pbTarget,
        PBYTE pbDetour,
        PBYTE *ppbRealTrampoline,
        PBYTE *ppbRealTarget,
        PBYTE *ppbRealDetour);

    BOOL  WINAPI DetourFunctionWithTrampoline(PBYTE pbTrampoline,
        PBYTE pbDetour);

    BOOL  WINAPI DetourFunctionWithTrampolineEx(PBYTE pbTrampoline,
        PBYTE pbDetour,
        PBYTE *ppbRealTrampoline,
        PBYTE *ppbRealTarget);

    BOOL  WINAPI DetourRemove(PBYTE pbTrampoline, PBYTE pbDetour);

    ////////////////////////////////////////////////////////////// Code Functions.
    //
    PBYTE WINAPI DetourFindFunction(PCHAR pszModule, PCHAR pszFunction);
    PBYTE WINAPI DetourGetFinalCode(PBYTE pbCode, BOOL fSkipJmp);

    PBYTE WINAPI DetourCopyInstruction(PBYTE pbDst, PBYTE pbSrc, PBYTE *ppbTarget);
    PBYTE WINAPI DetourCopyInstructionEx(PBYTE pbDst,
        PBYTE pbSrc,
        PBYTE *ppbTarget,
        LONG *plExtra);

    ///////////////////////////////////////////////////// Loaded Binary Functions.
    //
    HMODULE WINAPI DetourEnumerateModules(HMODULE hModuleLast);
    PBYTE WINAPI DetourGetEntryPoint(HMODULE hModule);
    BOOL WINAPI DetourEnumerateExports(HMODULE hModule,
        PVOID pContext,
        PF_DETOUR_BINARY_EXPORT_CALLBACK pfExport);

    PBYTE WINAPI DetourFindPayload(HMODULE hModule, REFGUID rguid, DWORD *pcbData);
    DWORD WINAPI DetourGetSizeOfPayloads(HMODULE hModule);

    ///////////////////////////////////////////////// Persistent Binary Functions.
    //
    BOOL WINAPI DetourBinaryBindA(PCHAR pszFile, PCHAR pszDll, PCHAR pszPath);
    BOOL WINAPI DetourBinaryBindW(PWCHAR pwzFile, PWCHAR pwzDll, PWCHAR pwzPath);
#ifdef UNICODE
#define DetourBinaryBind  DetourBinaryBindW
#else
#define DetourBinaryBind  DetourBinaryBindA
#endif // !UNICODE

    PDETOUR_BINARY WINAPI DetourBinaryOpen(HANDLE hFile);
    PBYTE WINAPI DetourBinaryEnumeratePayloads(PDETOUR_BINARY pBinary,
        GUID *pGuid,
        DWORD *pcbData,
        DWORD *pnIterator);
    PBYTE WINAPI DetourBinaryFindPayload(PDETOUR_BINARY pBinary,
        REFGUID rguid,
        DWORD *pcbData);
    PBYTE WINAPI DetourBinarySetPayload(PDETOUR_BINARY pBinary,
        REFGUID rguid,
        PBYTE pbData,
        DWORD cbData);
    BOOL WINAPI DetourBinaryDeletePayload(PDETOUR_BINARY pBinary, REFGUID rguid);
    BOOL WINAPI DetourBinaryPurgePayloads(PDETOUR_BINARY pBinary);
    BOOL WINAPI DetourBinaryResetImports(PDETOUR_BINARY pBinary);
    BOOL WINAPI DetourBinaryEditImports(PDETOUR_BINARY pBinary,
        PVOID pContext,
        PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway,
        PF_DETOUR_BINARY_FILE_CALLBACK pfFile,
        PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol,
        PF_DETOUR_BINARY_FINAL_CALLBACK pfFinal);
    BOOL WINAPI DetourBinaryWrite(PDETOUR_BINARY pBinary, HANDLE hFile);
    BOOL WINAPI DetourBinaryClose(PDETOUR_BINARY pBinary);

    /////////////////////////////////////////////// First Chance Exception Filter.
    //
    LPTOP_LEVEL_EXCEPTION_FILTER WINAPI
        DetourFirstChanceExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelFilter);

    ///////////////////////////////////////////////// Create Process & Inject Dll.
    //
    typedef BOOL(WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)
        (LPCSTR lpApplicationName,
            LPSTR lpCommandLine,
            LPSECURITY_ATTRIBUTES lpProcessAttributes,
            LPSECURITY_ATTRIBUTES lpThreadAttributes,
            BOOL bInheritHandles,
            DWORD dwCreationFlags,
            LPVOID lpEnvironment,
            LPCSTR lpCurrentDirectory,
            LPSTARTUPINFOA lpStartupInfo,
            LPPROCESS_INFORMATION lpProcessInformation);

    typedef BOOL(WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)
        (LPCWSTR lpApplicationName,
            LPWSTR lpCommandLine,
            LPSECURITY_ATTRIBUTES lpProcessAttributes,
            LPSECURITY_ATTRIBUTES lpThreadAttributes,
            BOOL bInheritHandles,
            DWORD dwCreationFlags,
            LPVOID lpEnvironment,
            LPCWSTR lpCurrentDirectory,
            LPSTARTUPINFOW lpStartupInfo,
            LPPROCESS_INFORMATION lpProcessInformation);

    BOOL WINAPI DetourCreateProcessWithDllA(LPCSTR lpApplicationName,
        LPSTR lpCommandLine,
        LPSECURITY_ATTRIBUTES lpProcessAttributes,
        LPSECURITY_ATTRIBUTES lpThreadAttributes,
        BOOL bInheritHandles,
        DWORD dwCreationFlags,
        LPVOID lpEnvironment,
        LPCSTR lpCurrentDirectory,
        LPSTARTUPINFOA lpStartupInfo,
        LPPROCESS_INFORMATION lpProcessInformation,
        LPCSTR lpDllName,
        PDETOUR_CREATE_PROCESS_ROUTINEA
        pfCreateProcessA);

    BOOL WINAPI DetourCreateProcessWithDllW(LPCWSTR lpApplicationName,
        LPWSTR lpCommandLine,
        LPSECURITY_ATTRIBUTES lpProcessAttributes,
        LPSECURITY_ATTRIBUTES lpThreadAttributes,
        BOOL bInheritHandles,
        DWORD dwCreationFlags,
        LPVOID lpEnvironment,
        LPCWSTR lpCurrentDirectory,
        LPSTARTUPINFOW lpStartupInfo,
        LPPROCESS_INFORMATION lpProcessInformation,
        LPCWSTR lpDllName,
        PDETOUR_CREATE_PROCESS_ROUTINEW
        pfCreateProcessW);

#ifdef UNICODE
#define DetourCreateProcessWithDll  DetourCreateProcessWithDllW
#define PDETOUR_CREATE_PROCESS_ROUTINE     PDETOUR_CREATE_PROCESS_ROUTINEW
#else
#define DetourCreateProcessWithDll  DetourCreateProcessWithDllA
#define PDETOUR_CREATE_PROCESS_ROUTINE     PDETOUR_CREATE_PROCESS_ROUTINEA
#endif // !UNICODE

    BOOL WINAPI DetourContinueProcessWithDllA(HANDLE hProcess, LPCSTR lpDllName);
    BOOL WINAPI DetourContinueProcessWithDllW(HANDLE hProcess, LPCWSTR lpDllName);

#ifdef UNICODE
#define DetourContinueProcessWithDll    DetourContinueProcessWithDllW
#else
#define DetourContinueProcessWithDll    DetourContinueProcessWithDllA
#endif // !UNICODE
    //
    //////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif // __cplusplus

/////////////////////////////////////////////////////////////////// Old Names.
//
#define ContinueProcessWithDll            DetourContinueProcessWithDll
#define ContinueProcessWithDllA           DetourContinueProcessWithDllA
#define ContinueProcessWithDllW           DetourContinueProcessWithDllW
#define CreateProcessWithDll              DetourCreateProcessWithDll
#define CreateProcessWithDllA             DetourCreateProcessWithDllA
#define CreateProcessWithDllW             DetourCreateProcessWithDllW
#define DETOUR_TRAMPOLINE_WO_TARGET       DETOUR_TRAMPOLINE_EMPTY
#define DetourBinaryPurgePayload          DetourBinaryPurgePayloads
#define DetourEnumerateExportsForInstance DetourEnumerateExports
#define DetourEnumerateInstances          DetourEnumerateModules
#define DetourFindEntryPointForInstance   DetourGetEntryPoint
#define DetourFindFinalCode               DetourGetFinalCode
#define DetourFindPayloadInBinary         DetourFindPayload
#define DetourGetSizeOfBinary             DetourGetSizeOfPayloads
#define DetourRemoveWithTrampoline        DetourRemove
#define PCREATE_PROCESS_ROUTINE           PDETOUR_CREATE_PROCESS_ROUTINE
#define PCREATE_PROCESS_ROUTINEA          PDETOUR_CREATE_PROCESS_ROUTINEA
#define PCREATE_PROCESS_ROUTINEW          PDETOUR_CREATE_PROCESS_ROUTINEW
//

//////////////////////////////////////////////// Detours Internal Definitions.
//
#ifdef __cplusplus
#ifdef DETOURS_INTERNAL

//////////////////////////////////////////////////////////////////////////////
//
#ifdef IMAGEAPI // defined by IMAGEHLP.H
typedef LPAPI_VERSION(NTAPI *PF_ImagehlpApiVersionEx)(LPAPI_VERSION AppVersion);

typedef BOOL(NTAPI *PF_SymInitialize)(IN HANDLE hProcess,
    IN LPSTR UserSearchPath,
    IN BOOL fInvadeProcess);
typedef DWORD(NTAPI *PF_SymSetOptions)(IN DWORD SymOptions);
typedef DWORD(NTAPI *PF_SymGetOptions)(VOID);
typedef BOOL(NTAPI *PF_SymLoadModule)(IN HANDLE hProcess,
    IN HANDLE hFile,
    IN PSTR ImageName,
    IN PSTR ModuleName,
    IN DWORD BaseOfDll,
    IN DWORD SizeOfDll);
typedef BOOL(NTAPI *PF_SymGetModuleInfo)(IN HANDLE hProcess,
    IN DWORD dwAddr,
    OUT PIMAGEHLP_MODULE ModuleInfo);
typedef BOOL(NTAPI *PF_SymGetSymFromName)(IN HANDLE hProcess,
    IN LPSTR Name,
    OUT PIMAGEHLP_SYMBOL Symbol);
typedef BOOL(NTAPI *PF_BindImage)(IN LPSTR pszImageName,
    IN LPSTR pszDllPath,
    IN LPSTR pszSymbolPath);

typedef struct _DETOUR_SYM_INFO
{
    HANDLE                   hProcess;
    HMODULE                  hImageHlp;
    PF_ImagehlpApiVersionEx  pfImagehlpApiVersionEx;
    PF_SymInitialize         pfSymInitialize;
    PF_SymSetOptions         pfSymSetOptions;
    PF_SymGetOptions         pfSymGetOptions;
    PF_SymLoadModule         pfSymLoadModule;
    PF_SymGetModuleInfo      pfSymGetModuleInfo;
    PF_SymGetSymFromName     pfSymGetSymFromName;
    PF_BindImage             pfBindImage;
} DETOUR_SYM_INFO, *PDETOUR_SYM_INFO;

PDETOUR_SYM_INFO DetourLoadImageHlp(VOID);

#endif // IMAGEAPI

//////////////////////////////////////////////////////////////////////////////
//
class CDetourEnableWriteOnCodePage
{
public:
    CDetourEnableWriteOnCodePage(PBYTE pbCode, LONG cbCode = DETOUR_TRAMPOLINE_SIZE)
    {
        m_pbCode = pbCode;
        m_cbCode = cbCode;
        m_dwOldPerm = 0;
        m_hProcess = GetCurrentProcess();

        if (m_pbCode && m_cbCode) {
            if (!FlushInstructionCache(m_hProcess, pbCode, cbCode)) {
                return;
            }
            if (!VirtualProtect(pbCode,
                cbCode,
                PAGE_EXECUTE_READWRITE,
                &m_dwOldPerm)) {
                return;
            }
        }
    }

    ~CDetourEnableWriteOnCodePage()
    {
        if (m_dwOldPerm && m_pbCode && m_cbCode) {
            DWORD dwTemp = 0;
            if (!FlushInstructionCache(m_hProcess, m_pbCode, m_cbCode)) {
                return;
            }
            if (!VirtualProtect(m_pbCode, m_cbCode, m_dwOldPerm, &dwTemp)) {
                return;
            }
        }
    }

    BOOL SetPermission(DWORD dwPerms)
    {
        if (m_dwOldPerm && m_pbCode && m_cbCode) {
            m_dwOldPerm = dwPerms;
            return TRUE;
        }
        return FALSE;
    }

    BOOL IsValid(VOID)
    {
        return m_pbCode && m_cbCode && m_dwOldPerm;
    }

private:
    HANDLE  m_hProcess;
    PBYTE   m_pbCode;
    LONG    m_cbCode;
    DWORD   m_dwOldPerm;
};

//////////////////////////////////////////////////////////////////////////////
//
inline PBYTE DetourGenMovEax(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0xB8;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenMovEbx(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0xBB;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenMovEcx(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0xB9;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenMovEdx(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0xBA;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenMovEsi(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0xBE;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenMovEdi(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0xBF;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenMovEbp(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0xBD;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenMovEsp(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0xBC;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenPush(PBYTE pbCode, UINT32 nValue)
{
    *pbCode++ = 0x68;
    *((UINT32*&)pbCode)++ = nValue;
    return pbCode;
}

inline PBYTE DetourGenPushad(PBYTE pbCode)
{
    *pbCode++ = 0x60;
    return pbCode;
}

inline PBYTE DetourGenPopad(PBYTE pbCode)
{
    *pbCode++ = 0x61;
    return pbCode;
}

inline PBYTE DetourGenJmp(PBYTE pbCode, PBYTE pbJmpDst, PBYTE pbJmpSrc = 0)
{
    if (pbJmpSrc == 0) {
        pbJmpSrc = pbCode;
    }
    *pbCode++ = 0xE9;
    *((INT32*&)pbCode)++ = pbJmpDst - (pbJmpSrc + 5);
    return pbCode;
}

inline PBYTE DetourGenCall(PBYTE pbCode, PBYTE pbJmpDst, PBYTE pbJmpSrc = 0)
{
    if (pbJmpSrc == 0) {
        pbJmpSrc = pbCode;
    }
    *pbCode++ = 0xE8;
    *((INT32*&)pbCode)++ = pbJmpDst - (pbJmpSrc + 5);
    return pbCode;
}

inline PBYTE DetourGenBreak(PBYTE pbCode)
{
    *pbCode++ = 0xcc;
    return pbCode;
}

inline PBYTE DetourGenRet(PBYTE pbCode)
{
    *pbCode++ = 0xc3;
    return pbCode;
}

inline PBYTE DetourGenNop(PBYTE pbCode)
{
    *pbCode++ = 0x90;
    return pbCode;
}
#endif DETOURS_INTERAL
#endif // __cplusplus

#endif // _DETOURS_H_
//
////////////////////////////////////////////////////////////////  End of File.
cDraw.h
C++:
#pragma once
#include "Header.h"
#define C_Text (DT_CENTER|DT_NOCLIP)
#define L_Text (DT_LEFT|DT_NOCLIP)
#define R_Text (DT_RIGHT|DT_NOCLIP)

static struct _Keys
{
    bool        bPressed;
    DWORD       dwStartTime;
}
kPressingKeys[256];

class cDraw
{
public:
    cDraw(void);
    bool Show;
    ID3DXFont* pFont;
    LPD3DXLINE pLine;
    BOOL  IsInBox(int x, int y, int w, int h);
    BOOL  State_Key(int Key, DWORD dwTimeOut);
    void  InitFont(CHAR* szFontFamily, int W, DWORD Stile, IDirect3DDevice9* mDevice);
    void  Engine_Text(int x, int y, DWORD color, LPSTR text, DWORD ST);
    void  Engine_Line(long Xa, long Ya, long Xb, long Yb, int Width, D3DCOLOR Color);
    void  Engine_Box(int x, int y, int w, int h, D3DCOLOR Color, LPDIRECT3DDEVICE9 m_pD3Ddev);
    void  Engine_Border(int x, int y, int w, int h, int s, D3DCOLOR Color, LPDIRECT3DDEVICE9 m_pD3Ddev);
    void  SHOW_MENU(LPDIRECT3DDEVICE9 pDevice);
    void  draw(DWORD KEY, LPDIRECT3DDEVICE9 pDevice);
  
  
    void  Engine_Vibor(int x, int y, int &var, LPSTR text, char *text2, char *text3, char *text4, char *text5, char *text6, char *text7, LPDIRECT3DDEVICE9 pDevice);
    void  Engine_Vibor_Knopki(int x, int y, int &var, LPSTR text, char *text2, char *text3, char *text4, char *text5, char *text6, char *text7, char *text8, char *text9, LPDIRECT3DDEVICE9 pDevice);
    void  Engine_Vibor_Prizok(int x, int y, int &var, LPSTR text, char *text2, char *text3, LPDIRECT3DDEVICE9 pDevice);
    void  MV_Menu(int x, int y, LPSTR text, LPDIRECT3DDEVICE9 pDevice);
    void  MV_MenuPanel(int x, int y, LPSTR text, LPDIRECT3DDEVICE9 pDevice);
    void  MV_MenuDop(int x, int y, LPSTR text, LPDIRECT3DDEVICE9 pDevice);
    void  MV_MenuDopForInfo(int x, int y, LPSTR text, LPDIRECT3DDEVICE9 pDevice);
    void  Engine_Button(int x, int y, bool &mv, LPSTR text, IDirect3DDevice9* pDevice);
    void  Engine_CheckBox(int x, int y, bool &mv, LPSTR text, IDirect3DDevice9* pDevice);

};
cDraw.cpp
C++:
#include "cDraw.h"
#include "Header.h"

cDraw::cDraw(void)
{
    Show = true;
}

void  cDraw::InitFont(CHAR* szFontFamily, int W, DWORD Stile, IDirect3DDevice9* mDevice)
{
    D3DXCreateFont(mDevice, W, 0, Stile, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, szFontFamily, &pFont);
}

void  cDraw::Engine_Text(int x, int y, DWORD color, LPSTR text, DWORD ST)
{
    RECT rect, rect2;
    SetRect(&rect, x, y, x, y);
    pFont->DrawTextA(NULL, text, -1, &rect, ST, color);
    SetRect(&rect, x, y, x, y);
}

void  cDraw::Engine_Box(int x, int y, int w, int h, D3DCOLOR Color, IDirect3DDevice9* mDevice)
{
    D3DRECT rec;
    rec.x1 = x;
    rec.x2 = x + w;
    rec.y1 = y;
    rec.y2 = y + h;
    mDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
    mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
    mDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, D3DPT_TRIANGLESTRIP);
    mDevice->Clear(1, &rec, D3DCLEAR_TARGET, Color, 1, 1);
}


void  cDraw::Engine_Border(int x, int y, int w, int h, int s, D3DCOLOR Color, IDirect3DDevice9* mDevice)
{
    Engine_Box(x, y, s, h, Color, mDevice);
    Engine_Box(x, y + h, w, s, Color, mDevice);
    Engine_Box(x, y, w, s, Color, mDevice);
    Engine_Box(x + w, y, s, h + s, Color, mDevice);
}

BOOL  cDraw::IsInBox(int x, int y, int w, int h)
{
    POINT MousePosition;
    GetCursorPos(&MousePosition);
    ScreenToClient(GetForegroundWindow(), &MousePosition);
    return(MousePosition.x >= x && MousePosition.x <= x + w && MousePosition.y >= y && MousePosition.y <= y + h);
}

void  cDraw::Engine_Line(long Xa, long Ya, long Xb, long Yb, int Width, D3DCOLOR Color)
{
    D3DXVECTOR2 vLine[2];
    pLine->SetAntialias(0);
    pLine->SetWidth(Width);
    pLine->Begin();
    vLine[0][0] = Xa;
    vLine[0][1] = Ya;
    vLine[1][0] = Xb;
    vLine[1][1] = Yb;
    pLine->Draw(vLine, 2, Color);
    pLine->End();
}

BOOL cDraw::State_Key(int Key, DWORD dwTimeOut)
{
    if (HIWORD(GetKeyState(Key)))
    {
        if (!kPressingKeys[Key].bPressed || (kPressingKeys[Key].dwStartTime && (kPressingKeys[Key].dwStartTime + dwTimeOut) <= GetTickCount()))
        {
            kPressingKeys[Key].bPressed = TRUE;
            if (dwTimeOut > NULL)
                kPressingKeys[Key].dwStartTime = GetTickCount();
            return TRUE;
        }
    }
    else
        kPressingKeys[Key].bPressed = FALSE;
    return FALSE;
}

void  cDraw::draw(DWORD KEY, LPDIRECT3DDEVICE9  pDevice)
{
    ESP(pDevice);
  
}

#define TheColorit        D3DCOLOR_ARGB(255,255,255,255)

#define click (GetAsyncKeyState(0x01)&1)

void cDraw::Engine_Vibor(int x, int y, int &var, LPSTR text, char *text2, char *text3, char *text4, char *text5, char *text6, char *text7, LPDIRECT3DDEVICE9 pDevice) //тест выбора
{
    /* правая кнопка */
    Engine_Border(x + 142, y + 30, 16, 16, 1, Green, pDevice); //обводка чекбокса выбора
    if (IsInBox(x + 142, y + 30, 16, 16))
    {
        Engine_Border(x + 142, y + 30, 16, 16, 1, Lime, pDevice); //обводка чекбокса выбора
        if (click)
        {
            if (var != 5)var++;
            else var = 0;
        }
    }
    /* левая кнопка */
    Engine_Border(x + 30, y + 30, 16, 16, 1, Green, pDevice); //обводка чекбокса выбора
    if (IsInBox(x + 30, y + 30, 16, 16))
    {
        Engine_Border(x + 30, y + 30, 16, 16, 1, Lime, pDevice); //обводка чекбокса выбора
        if (click)
        {
            if (var != 0)var--;
            else var = 5;
        }
    }
    switch (var)
    {
    case 0: text = text2; break;
    case 1: text = text3; break;
    case 2: text = text4; break;
    case 3: text = text5; break;
    case 4: text = text6; break;
    case 5: text = text7; break;
    }
    Engine_Text(x + 95, y + 30, Lime, text, C_Text);//текст в центре, между стрелками
}

void cDraw::Engine_Vibor_Knopki(int x, int y, int &var, LPSTR text, char *text2, char *text3, char *text4, char *text5, char *text6, char *text7, char *text8, char *text9, LPDIRECT3DDEVICE9 pDevice) //тест выбора
{
    /* правая кнопка */
    Engine_Border(x + 142, y + 30, 16, 16, 1, Green, pDevice); //обводка чекбокса выбора
    if (IsInBox(x + 142, y + 30, 16, 16))
    {
        Engine_Border(x + 142, y + 30, 16, 16, 1, Lime, pDevice); //обводка чекбокса выбора
        if (click)
        {
            if (var != 7)var++;
            else var = 0;
        }
    }
    /* левая кнопка */
    Engine_Border(x + 30, y + 30, 16, 16, 1, Green, pDevice); //обводка чекбокса выбора
    if (IsInBox(x + 30, y + 30, 16, 16))
    {
        Engine_Border(x + 30, y + 30, 16, 16, 1, Lime, pDevice); //обводка чекбокса выбора
        if (click)
        {
            if (var != 0)var--;
            else var = 7;
        }
    }
    switch (var)
    {
    case 0: text = text2; break;
    case 1: text = text3; break;
    case 2: text = text4; break;
    case 3: text = text5; break;
    case 4: text = text6; break;
    case 5: text = text7; break;
    case 6: text = text8; break;
    case 7: text = text9; break;
    }
    Engine_Text(x + 95, y + 30, Lime, text, C_Text);//Заголовок меню находящийся на его шапке
}


void cDraw::Engine_Vibor_Prizok(int x, int y, int &var, LPSTR text, char *text2, char *text3, LPDIRECT3DDEVICE9 pDevice) //тест выбора
{
    /* правая кнопка */
    Engine_Border(x + 142, y + 30, 16, 16, 1, Green, pDevice); //обводка чекбокса выбора
    if (IsInBox(x + 142, y + 30, 16, 16))
    {
        Engine_Border(x + 142, y + 30, 16, 16, 1, Lime, pDevice); //обводка чекбокса выбора
        if (click)
        {
            if (var != 2)var++;
            else var = 0;
        }
    }
    /* левая кнопка */
    Engine_Border(x + 30, y + 30, 16, 16, 1, Green, pDevice); //обводка чекбокса выбора
    if (IsInBox(x + 30, y + 30, 16, 16))
    {
        Engine_Border(x + 30, y + 30, 16, 16, 1, Lime, pDevice); //обводка чекбокса выбора
        if (click)
        {
            if (var != 0)var--;
            else var = 2;
        }
    }
    switch (var)
    {
    case 0: text = text2; break;
    case 1: text = text3; break;
    }
    Engine_Text(x + 95, y + 30, Lime, text, C_Text);//Заголовок меню находящийся на его шапке
}

void cDraw::MV_Menu(int x, int y, LPSTR text, LPDIRECT3DDEVICE9 pDevice)
{
    Engine_Box(x, y, 155, 25, DARK2, pDevice);//Основной бокс на котором строится все меню
    Engine_Text(x + 10, y + 6, Lime, text, L_Text);//Заголовок меню находящийся на его шапке
    Engine_Border(x, y, 155, 24, 1, GREEN, pDevice);//обводка шапки меню
}
void cDraw::MV_MenuPanel(int x, int y, LPSTR text, LPDIRECT3DDEVICE9 pDevice) //бокс для основного меню с функциями
{
    Engine_Box(x, y, 155, 153, DARK4, pDevice);//фон
}
void cDraw::MV_MenuDop(int x, int y, LPSTR text, LPDIRECT3DDEVICE9 pDevice) //бокс для основного меню с функциями
{
    Engine_Box(x + 1, y + 1, 154, 45, DARK4, pDevice);//фон
}
void cDraw::MV_MenuDopForInfo(int x, int y, LPSTR text, LPDIRECT3DDEVICE9 pDevice) //бокс для основного меню с функциями
{
    Engine_Box(x + 1, y + 1, 154, 135, DARK4, pDevice);//фон
}

#define Серый  D3DCOLOR_ARGB(160, 46, 46, 46)

void  cDraw::Engine_CheckBox(int x, int y, bool &mv, LPSTR text, IDirect3DDevice9* pDevice)
{
    Engine_Text(x + 4, y + 3, AliceBlue, text, L_Text);
    Engine_Border(x + 135, y + 1, 16, 16, 1, Green, pDevice); //обводка чекбокса выбора
    Engine_Border(x + 2, y - 1, 151, 20, 1, Green, pDevice); //выделение названия функции

    if (IsInBox(x + 2, y - 1, 151, 20)) //если строка с названием выделена, то изменяем цвет обводки
    {
        Engine_Border(x + 135, y + 1, 16, 16, 1, Lime, pDevice); //обводка чекбокса выбора
        Engine_Border(x + 2, y - 1, 151, 20, 1, Lime, pDevice); //выделение названия функции
    }

    if (IsInBox(x + 135, y + 1, 16, 16))
        if (State_Key(VK_LBUTTON, 1000))
            mv = !mv;

    if (mv)
        Engine_Box(x + 140, y + 7, 7, 6, GREEN, pDevice); //ставим галочку в чекбоксе
}

visual.h
C++:
#include <sstream>

int XMP(LPD3DXFONT pFont)
{
    POINT MousePosition;
    GetCursorPos(&MousePosition);
    ScreenToClient(GetForegroundWindow(), &MousePosition);
    return MousePosition.x;
}
int YMP(LPD3DXFONT pFont)
{
    POINT MousePosition;
    GetCursorPos(&MousePosition);
    ScreenToClient(GetForegroundWindow(), &MousePosition);
    return MousePosition.y;
}

bool ScreenTransform(VEC3& from, VEC3& to) // tots not pasted
{
  

  
    float w;

    to.x = m_render.ptr_viewMatrix->m_ViewMatrix._11 * from.x + m_render.ptr_viewMatrix->m_ViewMatrix._12 * from.y + m_render.ptr_viewMatrix->m_ViewMatrix._13 * from.z + m_render.ptr_viewMatrix->m_ViewMatrix._14;
    to.y = m_render.ptr_viewMatrix->m_ViewMatrix._21 * from.x + m_render.ptr_viewMatrix->m_ViewMatrix._22 * from.y + m_render.ptr_viewMatrix->m_ViewMatrix._23 * from.z + m_render.ptr_viewMatrix->m_ViewMatrix._24;
    w = m_render.ptr_viewMatrix->m_ViewMatrix._41 * from.x + m_render.ptr_viewMatrix->m_ViewMatrix._42 * from.y + m_render.ptr_viewMatrix->m_ViewMatrix._43 * from.z + m_render.ptr_viewMatrix->m_ViewMatrix._44;
    to.z = 5.1f;



    bool behind = false;

    if (w < 0.001f)
    {
        behind = true;
        to.x *= 100000;
        to.y *= 100000;
    }
    else
    {
        behind = false;
        float invw = 1.0f / w;
        to.x *= invw;
        to.y *= invw;
    }

    return behind;


}
//int wndd = 0;
RECT rect;

float mx = 0;
float my = 0;

bool WorldToScreen(VEC3& from, VEC3& to)
{
  
    if (!ScreenTransform(from, to))
    {
        HWND d = FindWindow(0, "Counter-Strike Source");
        int ScreenWidth, ScreenHeight;

        GetWindowRect(d, &rect);
        ScreenWidth = (int)(rect.right - rect.left);
        ScreenHeight = (int)(rect.bottom - rect.top);
        float x = ScreenWidth / 2;
        float y = ScreenHeight / 2;
        x += 0.5 * to.x * ScreenWidth + 0.5;
        y -= 0.5 * to.y * ScreenHeight + 0.5;
        to.x = x;
        to.y = y;
        return true;
    }

    return false;
}

void  cDraw::ESP(LPDIRECT3DDEVICE9  pDevice)
{
  
  
}
Colors.h
C++:
#pragma once


#define  BLUEMAZAY        D3DCOLOR_ARGB(255, 21,  56,  128)
#define     ORANGE              D3DCOLOR_ARGB(255,255,125,0)
#define     YELLOW           D3DCOLOR_ARGB(255,255,255,0)
#define     GREY             D3DCOLOR_ARGB(255,128,128,128)
#define     PURPLE           D3DCOLOR_ARGB(255,125,0,255)
#define     WHITE              D3DCOLOR_ARGB(255, 255, 255, 255)
#define     RED              D3DCOLOR_ARGB(255, 255, 000, 000)
#define     GREEN              D3DCOLOR_ARGB(255, 000, 210, 000)
#define     BLUE                D3DCOLOR_ARGB(255, 000, 000, 255)
#define     BLACK              D3DCOLOR_ARGB(255, 000, 000, 000)
#define  DARK1            D3DCOLOR_ARGB(255, 10, 10, 10)
#define  DARK2            D3DCOLOR_ARGB(255, 15, 15, 15)
#define  DARK3            D3DCOLOR_ARGB(255, 20, 20, 20)
#define  DARK4            D3DCOLOR_ARGB(255, 25, 25, 25)
#define  DARK5            D3DCOLOR_ARGB(255, 30, 30, 30)
#define  DARK6            D3DCOLOR_ARGB(255, 35, 35, 35)
#define  DARK7            D3DCOLOR_ARGB(255, 40, 40, 40)
#define  DARK8            D3DCOLOR_ARGB(255, 45, 45, 45)
#define  DARK9            D3DCOLOR_ARGB(255, 50, 50, 50)
#define  DARK10           D3DCOLOR_ARGB(255, 60, 60, 60)
#define  DARK11           D3DCOLOR_ARGB(255, 65, 65, 65)
#define  DARK12           D3DCOLOR_ARGB(255, 70, 70, 70)
#define  DARK13           D3DCOLOR_ARGB(255, 75, 75, 75)
#define  DARK14           D3DCOLOR_ARGB(255, 80, 80, 80)
#define  DARK15           D3DCOLOR_ARGB(255, 85, 85, 85)
#define  DARK16           D3DCOLOR_ARGB(255, 90, 90, 90)
#define  DARK18           D3DCOLOR_ARGB(255, 130, 130, 130)
#define  DARK20           D3DCOLOR_ARGB(255, 150, 150, 150)
#define  WINDOWS          D3DCOLOR_ARGB(255, 176 ,  30 ,  58 )
#define  WINDOWS2         D3DCOLOR_ARGB(255, 176 ,  20 ,  48 )

#define     STYLE          D3DCOLOR_ARGB(255,10,140,50)

#define  DARK30           D3DCOLOR_ARGB(255, 62, 62, 62)

#define  DARK17            D3DCOLOR_ARGB(220, 40, 40, 40)
#define  DARK27            D3DCOLOR_ARGB(200, 40, 40, 40)
#define  DARK37            D3DCOLOR_ARGB(160, 40, 40, 40)

//-----------------------------------------------------------------------------
// Exam: Colors::AliceBlue
// Desc: Цвет
// Сonc: Menu
//-----------------------------------------------------------------------------

enum Colors : D3DCOLOR
{
    Green = 0xFF0E8D19,
    GreenGray = 0xFF2D432D,
    AliceBlue = 0xFFF0F8FF,
    AntiqueWhite = 0xFFFAEBD7,
    Aqua = 0xFF00FFFF,
    Aquamarine = 0xFF7FFFD4,
    Azure = 0xFFF0FFFF,
    Beige = 0xFFF5F5DC,
    Bisque = 0xFFFFE4C4,
    BlanchedAlmond = 0xFFFFEBCD,
    BlueViolet = 0xFF8A2BE2,
    Brown = 0xFFA52A2A,
    BurlyWood = 0xFFDEB887,
    CadetBlue = 0xFF5F9EA0,
    Chartreuse = 0xFF7FFF00,
    Chocolate = 0xFFD2691E,
    Coral = 0xFFFF7F50,
    CornflowerBlue = 0xFF6495ED,
    Cornsilk = 0xFFFFF8DC,
    Crimson = 0xFFDC143C,
    Cyan = 0xFF00FFFF,
    DarkBlue = 0xFF00008B,
    DarkCyan = 0xFF008B8B,
    DarkGoldenrod = 0xFFB8860B,
    DarkGray = 0xFFA9A9A9,
    DarkGreen = 0xFF006400,
    DarkKhaki = 0xFFBDB76B,
    DarkMagenta = 0xFF8B008B,
    DarkOliveGreen = 0xFF556B2F,
    DarkOrange = 0xFFFF8C00,
    DarkOrchid = 0xFF9932CC,
    DarkRed = 0xFF8B0000,
    DarkSalmon = 0xFFE9967A,
    DarkSeaGreen = 0xFF8FBC8B,
    DarkSlateBlue = 0xFF483D8B,
    DarkSlateGray = 0xFF2F4F4F,
    DarkTurquoise = 0xFF00CED1,
    DarkViolet = 0xFF9400D3,
    DeepPink = 0xFFFF1493,
    DeepSkyBlue = 0xFF00BFFF,
    DimGray = 0xFF696969,
    DodgerBlue = 0xFF1E90FF,
    Firebrick = 0xFFB22222,
    FloralWhite = 0xFFFFFAF0,
    ForestGreen = 0xFF228B22,
    Fuchsia = 0xFFFF00FF,
    Gainsboro = 0xFFDCDCDC,
    GhostWhite = 0xFFF8F8FF,
    GOLD = 0xFFFFD700,
    Goldenrod = 0xFFDAA520,
    GreenYellow = 0xFFADFF2F,
    Honeydew = 0xFFF0FFF0,
    HotPink = 0xFFFF69B4,
    IndianRed = 0xFFCD5C5C,
    Indigo = 0xFF4B0082,
    Ivory = 0xFFFFFFF0,
    Khaki = 0xFFF0E68C,
    Lavender = 0xFFE6E6FA,
    LavenderBlush = 0xFFFFF0F5,
    LawnGreen = 0xFF7CFC00,
    LemonChiffon = 0xFFFFFACD,
    LightBlue = 0xFFADD8E6,
    LightCoral = 0xFFF08080,
    LightCyan = 0xFFE0FFFF,
    LightGoldenrodYellow = 0xFFFAFAD2,
    LightGray = 0xFFD3D3D3,
    LightGreen = 0xFF90EE90,
    LightPink = 0xFFFFB6C1,
    LightSalmon = 0xFFFFA07A,
    LightSeaGreen = 0xFF20B2AA,
    LightSkyBlue = 0xFF87CEFA,
    LightSlateGray = 0xFF778899,
    LightSteelBlue = 0xFFB0C4DE,
    LightYellow = 0xFFFFFFE0,
    Lime = 0xFF00FF00,
    LimeGreen = 0xFF32CD32,
    Linen = 0xFFFAF0E6,
    Magenta = 0xFFFF00FF,
    Maroon = 0xFF800000,
    MediumAquamarine = 0xFF66CDAA,
    MediumBlue = 0xFF0000CD,
    MediumOrchid = 0xFFBA55D3,
    MediumPurple = 0xFF9370DB,
    MediumSeaGreen = 0xFF3CB371,
    MediumSlateBlue = 0xFF7B68EE,
    MediumSpringGreen = 0xFF00FA9A,
    MediumTurquoise = 0xFF48D1CC,
    MediumVioletRed = 0xFFC71585,
    MidnightBlue = 0xFF191970,
    MintCream = 0xFFF5FFFA,
    MistyRose = 0xFFFFE4E1,
    Moccasin = 0xFFFFE4B5,
    NavajoWhite = 0xFFFFDEAD,
    Navy = 0xFF000080,
    OldLace = 0xFFFDF5E6,
    Olive = 0xFF808000,
    OliveDrab = 0xFF6B8E23,
    Orange = 0xFFFFA500,
    OrangeRed = 0xFFFF4500,
    Orchid = 0xFFDA70D6,
    PaleGoldenrod = 0xFFEEE8AA,
    PaleGreen = 0xFF98FB98,
    PaleTurquoise = 0xFFAFEEEE,
    PaleVioletRed = 0xFFDB7093,
    PapayaWhip = 0xFFFFEFD5,
    PeachPuff = 0xFFFFDAB9,
    Peru = 0xFFCD853F,
    Pink = 0xFFFFC0CB,
    Plum = 0xFFDDA0DD,
    PowderBlue = 0xFFB0E0E6,
    RosyBrown = 0xFFBC8F8F,
    RoyalBlue = 0xFF4169E1,
    SaddleBrown = 0xFF8B4513,
    Salmon = 0xFFFA8072,
    SandyBrown = 0xFFF4A460,
    SeaGreen = 0xFF2E8B57,
    SeaShell = 0xFFFFF5EE,
    Sienna = 0xFFA0522D,
    Silver = 0xFFC0C0C0,
    SkyBlue = 0xFF87CEEB,
    SlateBlue = 0xFF6A5ACD,
    SlateGray = 0xFF708090,
    Snow = 0xFFFFFAFA,
    SpringGreen = 0xFF00FF7F,
    SteelBlue = 0xFF4682B4,
    Tan = 0xFFD2B48C,
    Teal = 0xFF008080,
    Thistle = 0xFFD8BFD8,
    Tomato = 0xFFFF6347,
    Transparent = 0x00FFFFFF,
    Turquoise = 0xFF40E0D0,
    Violet = 0xFFEE82EE,
    Wheat = 0xFFF5DEB3,
    WhiteSmoke = 0xFFF5F5F5,
    YellowGreen = 0xFF9ACD32
};
Header.h
C++:
#include <Windows.h> ///| windows API


#include <iostream>                                                        //    Для работы с консолью
#include <IO.H>                                                         //      _open_osfhandle()
#include <FCNTL.H>                                                      //      _O_TEXT
#include <conio.h>                                                        //

#define Start_Therad(Function) CreateThread(0,0,(LPTHREAD_START_ROUTINE)Function,0,0,0); //Запуск функции в новом потоке

#include <d3d9.h>                            //|
#include <d3dx9.h>                            //|
#define D3DparamX        , UINT paramx        //|            DIRECTX
#define D3DparamvalX    , paramx            //|               9
#pragma comment(lib, "d3d9.lib")            //|
#pragma comment(lib, "d3dx9.lib")            //|
#pragma comment(lib, "detours.lib")
#include "detours.h"
#include "Colors.h"

class VEC3;
class VEC2;

class VEC3
{
public:
    float x, y, z;

};
class VEC2
{
public:
    float x, y;

};
Теперь видосики
Первый урок: поиск базового адреса и создание класса
Второй урок: поиск видовой матрици
Третий урок: Делаем Esp Line и 2dBox
 

Вложения

  • detours.7z
    37.4 KB · Просмотры: 47

deropleat

Известный
105
56
cDraw.cpp
C++:
#define Серый  D3DCOLOR_ARGB(160, 46, 46, 46)
:hah:

Я предлагаю сделать более удобный хук таблиц, не Detour.

VMTHook.h
C++:
#pragma once

#include <cstdint>
#include <cstddef>
#include <cstring>
#include <memory>

class VMTHook
{
private:
    std::uintptr_t** BaseClass = nullptr;
    std::unique_ptr<std::uintptr_t[]> CurrentVTF = nullptr;
    std::uintptr_t* OriginalVTF = nullptr;
    std::size_t TotalFuncs = 0;
public:
    VMTHook(void) = default;
    VMTHook(void* BaseClass)
    {
        this->BaseClass = static_cast<std::uintptr_t**>(BaseClass);
        while (static_cast<std::uintptr_t*>(*this->BaseClass)[this->TotalFuncs])++this->TotalFuncs;
        const std::size_t TableSize = this->TotalFuncs * sizeof(std::uintptr_t);
        this->OriginalVTF = *this->BaseClass;
        this->CurrentVTF = std::make_unique<std::uintptr_t[]>(this->TotalFuncs);
        std::memcpy(this->CurrentVTF.get(), this->OriginalVTF, TableSize);
        *this->BaseClass = this->CurrentVTF.get();
    };
    ~VMTHook()
    {
        *this->BaseClass = this->OriginalVTF;
    };
    template <typename Fn = void*> inline const Fn GetOrigIndex(std::size_t FunctionIndex)
    {
        return reinterpret_cast<Fn>(this->OriginalVTF[FunctionIndex]);
    }
    inline bool TableIndexHook(void* new_function, const std::size_t FunctionIndex)
    {
        if (FunctionIndex > this->TotalFuncs) return false;
        this->CurrentVTF[FunctionIndex] = reinterpret_cast<std::uintptr_t>(new_function);
        return true;
    }
    inline bool TableIndexUnHook(const std::size_t FunctionIndex)
    {
        if (FunctionIndex > this->TotalFuncs) return false;
        this->CurrentVTF[FunctionIndex] = this->OriginalVTF[FunctionIndex];
        return true;
    }
    inline std::size_t GetMaxIndex()
    {
        return this->TotalFuncs;
    }
};

Отрывок из главного потока main.cpp
0x0 - адрес девайса.
C++:
IDirect3DDevice9* pDevice = *(IDirect3DDevice9**)0x0;
MyDevice = new VMTHook(pDevice);
MyDevice->TableIndexHook(Hooks::Reset, 16);
MyDevice->TableIndexHook(Hooks::Present, 17);

Заодно, можно будет сделать урок как искать адрес на девайс и тому подобное.
 

gresearch

Новичок
Автор темы
9
19
cDraw.cpp
C++:
#define Серый  D3DCOLOR_ARGB(160, 46, 46, 46)
:hah:

Я предлагаю сделать более удобный хук таблиц, не Detour.

VMTHook.h
C++:
#pragma once

#include <cstdint>
#include <cstddef>
#include <cstring>
#include <memory>

class VMTHook
{
private:
    std::uintptr_t** BaseClass = nullptr;
    std::unique_ptr<std::uintptr_t[]> CurrentVTF = nullptr;
    std::uintptr_t* OriginalVTF = nullptr;
    std::size_t TotalFuncs = 0;
public:
    VMTHook(void) = default;
    VMTHook(void* BaseClass)
    {
        this->BaseClass = static_cast<std::uintptr_t**>(BaseClass);
        while (static_cast<std::uintptr_t*>(*this->BaseClass)[this->TotalFuncs])++this->TotalFuncs;
        const std::size_t TableSize = this->TotalFuncs * sizeof(std::uintptr_t);
        this->OriginalVTF = *this->BaseClass;
        this->CurrentVTF = std::make_unique<std::uintptr_t[]>(this->TotalFuncs);
        std::memcpy(this->CurrentVTF.get(), this->OriginalVTF, TableSize);
        *this->BaseClass = this->CurrentVTF.get();
    };
    ~VMTHook()
    {
        *this->BaseClass = this->OriginalVTF;
    };
    template <typename Fn = void*> inline const Fn GetOrigIndex(std::size_t FunctionIndex)
    {
        return reinterpret_cast<Fn>(this->OriginalVTF[FunctionIndex]);
    }
    inline bool TableIndexHook(void* new_function, const std::size_t FunctionIndex)
    {
        if (FunctionIndex > this->TotalFuncs) return false;
        this->CurrentVTF[FunctionIndex] = reinterpret_cast<std::uintptr_t>(new_function);
        return true;
    }
    inline bool TableIndexUnHook(const std::size_t FunctionIndex)
    {
        if (FunctionIndex > this->TotalFuncs) return false;
        this->CurrentVTF[FunctionIndex] = this->OriginalVTF[FunctionIndex];
        return true;
    }
    inline std::size_t GetMaxIndex()
    {
        return this->TotalFuncs;
    }
};

Отрывок из главного потока main.cpp
0x0 - адрес девайса.
C++:
IDirect3DDevice9* pDevice = *(IDirect3DDevice9**)0x0;
MyDevice = new VMTHook(pDevice);
MyDevice->TableIndexHook(Hooks::Reset, 16);
MyDevice->TableIndexHook(Hooks::Present, 17);

Заодно, можно будет сделать урок как искать адрес на девайс и тому подобное.
Думаю с Overlay побаловаться
 
Статус
В этой теме нельзя размещать новые ответы.