PHCreed

PHCreed Unlimitboard Online Tambayan
 
HomePortalCalendarGalleryFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 DIRECTX HACK CODE

Go down 
AuthorMessage
Admin
Admin
Admin
avatar

Posts : 92
Join date : 17/02/2013
Age : 23
Location : iloilo

PostSubject: DIRECTX HACK CODE    Wed Feb 27, 2013 6:53 pm

Code:
#pragma once

#include <Windows.h>
#include "d3d9.h"
#include <ctime> //for the clock
#include <iostream>

#define D3DHOOK_TEXTURES //comment this to disable texture hooking
#define MAX_MENU_ITEMS 5 //so you limit up to make sure everything else run smoothly

//MOVE THESE to the top
//these are just examples you can do your own

#define CUSTOM_CROSSHAIR 1
#define NO_RECOIL 2
#define UNLIM_AMMO 3
#define AUTO_FIRE 4
#define HIDE_MENU 5


const BYTE bRed[60] =
{
0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0x00, 0x00, 0x50};

const BYTE bGreen[60] =
{
0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x20, 0xA0, 0x00, 0x00, 0xFF, 0xFF
};

const BYTE bBlue[60] =
{
0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00
};

const BYTE bWhite[58] =
{
0x42, 0x4D, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0x00
};



//----------------------------------------------

class Hacks
{
public:
    int m_Stride;
    /*Function prototypes*/
    void Hacks::CreateFont(IDirect3DDevice9 *d3dDevice, std::string choiceFont);
    void Hacks::InitializeMenuItems();
    void Hacks::CreateTexture(IDirect3DDevice9 *d3dDevice, LPCVOID colour, UINT ColourSize, LPDIRECT3DTEXTURE9 *texture);
    void Hacks::Draw_Text(LPCSTR TextToDraw, int x, int y, D3DCOLOR Colour);
    void Hacks::DrawMenu(IDirect3DDevice9 *d3dDevice);
    void Hacks::DrawFilledRect(int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* d3dDevice);
    void Hacks::DrawBorderBox( int x, int y, int w, int h, int thickness, D3DCOLOR Colour, IDirect3DDevice9 *d3dDevice);
    void Hacks::KeyboardInput();
    void Hacks::ApplyWallHack(IDirect3DDevice9 *d3dDevice, D3DPRIMITIVETYPE device, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount);

   

    //used to get window size and other info
    D3DVIEWPORT9 g_ViewPort;

    //our font
    LPD3DXFONT m_font;

    //everything each hack needs bay bay
    struct d3dMenuHack
    {
        bool on;
        std::string name;
    };

    d3dMenuHack hack[MAX_MENU_ITEMS];
};

hack.cpp
Code:
#include "hacks.h";


/*--------------CHEAT RELATED VARS-------------------*/

int MenuIndex = 0;

// Create a colour for the text
D3DCOLOR fontRed = D3DCOLOR_ARGB(255, 255, 0, 0); 
D3DCOLOR fontGreen = D3DCOLOR_ARGB(255, 0, 255, 0);   
D3DCOLOR fontBlue = D3DCOLOR_ARGB(255, 0, 42, 255);   
D3DCOLOR fontWhite = D3DCOLOR_ARGB(255, 255, 255, 255); 
D3DCOLOR fontBlack = D3DCOLOR_ARGB(255, 0, 0, 0); 
/*---------------------------------------------------*/


void Hacks::CreateFont(IDirect3DDevice9 *d3dDevice, std::string choiceFont)
{
        D3DXCreateFont( d3dDevice, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET,
                OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
                choiceFont.c_str(), &m_font );
}

void Hacks::InitializeMenuItems()
{
   
    hack[CUSTOM_CROSSHAIR].name = " Crosshair";
    hack[NO_RECOIL].name = " No Recoil";
    hack[UNLIM_AMMO].name = " Unlimited Ammo";
    hack[AUTO_FIRE].name = "Auto Fire";
    hack[HIDE_MENU].name = " Hide hack [INSERT]";
    //make the hack visible by default
    hack[HIDE_MENU].on = false; //shows hack by default
}


void Hacks::CreateTexture(IDirect3DDevice9 *d3dDevice, LPCVOID colour, UINT ColourSize, LPDIRECT3DTEXTURE9 *texture)
{
    D3DXCreateTextureFromFileInMemory(d3dDevice, colour, ColourSize, texture);
}

void Hacks::DrawMenu(IDirect3DDevice9 *d3dDevice)
{
    if(!hack[HIDE_MENU].on)
    {
        //Add game name here, and put border around it
        DrawFilledRect( 55, 20, 200, 50, fontBlue, d3dDevice );
        DrawBorderBox(55, 20, 200, 50, 4, fontBlack, d3dDevice );
        Draw_Text("ANMSJHUN PSF hack", 190, 30, fontWhite);

        //draw back of our hack, transparent black
        DrawFilledRect( 30, 55, 250, (62*MAX_MENU_ITEMS), fontBlue, d3dDevice );
       
        //draw hack border
        DrawBorderBox(30, 55, 250, (62*MAX_MENU_ITEMS), 6/*was 6*/, fontBlack, d3dDevice );
        //Reset our time and update the text again in 2 secs
        int y = 40;
        for(int i = 0; i < MAX_MENU_ITEMS; i ++)
        {
            //Draw each box's back colour, this will be based on whether the hack is on e.g.
            //red means off and green means on
            DrawFilledRect( 45, 30+y, 220, 40, hack[i].on ? fontGreen : fontRed, d3dDevice );

            //draw box Around Each hack item If the item is highlighted it will show with a white border
            DrawBorderBox(45, 30+y, 220, 40, 4, fontBlack, d3dDevice );

            //draw White border to show the user which hack item is currently selected
            if(MenuIndex == i)
            {
                DrawBorderBox(41, 26+y, 228, 48, 4, fontWhite, d3dDevice );
            }

            //Ternary at its finest, if the  hack is on we display the text colour in green
            //otherwise its green
            //Draw_Text(hack[i].KeyAssigned.c_str(), 160 , 32+y, fontWhite);
            Draw_Text(hack[i].name.c_str(), 170 , 39+y, fontBlack);
            //Draw_Text(hack[i].state. c_str(), 355 , 32+y, hack[i].on ? fontGreen : fontRed);
            //used to position the next item below by 30 height units
            y+= 50;
        }
        Draw_Text("Select using arrow keys", 170, ((62*MAX_MENU_ITEMS)+7), fontWhite);
        Draw_Text("Turn ON/OFF [END] key", 170, ((62*MAX_MENU_ITEMS)+27), fontWhite);
    }
}

void Hacks::DrawBorderBox( int x, int y, int w, int h, int thickness, D3DCOLOR Colour, IDirect3DDevice9 *pDevice)
{
    //Top horiz line
    DrawFilledRect( x, y, w, thickness,  Colour, pDevice );
    //Left vertical line
    DrawFilledRect( x, y, thickness, h, Colour, pDevice );
    //right vertical line
    DrawFilledRect( (x + w), y, thickness, h, Colour, pDevice );
    //bottom horiz line
    DrawFilledRect( x, y + h, w+thickness, thickness, Colour, pDevice );
}


//We receive the 2-D Coordinates the colour and the device we want to use to draw those colours with
void Hacks::DrawFilledRect(int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* dev)
{
    //We create our rectangle to draw on screen
    D3DRECT BarRect = { x, y, x + w, y + h };
    //We clear that portion of the screen and display our rectangle
    dev->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_TARGET, color, 0, 0);
}


void Hacks::Draw_Text(LPCSTR TextToDraw, int x, int y, D3DCOLOR Colour)
{
    // Create a rectangle to indicate where on the screen it should be drawn
    RECT rct = {x- 120, y, x+ 120, y + 15};

    // Draw some text
    m_font->DrawText(NULL, TextToDraw, -1, &rct, DT_NOCLIP, Colour );
}


void Hacks::KeyboardInput()
{
    if(GetAsyncKeyState(VK_UP)&1)
    {
        if(MenuIndex > 0)
        {
            MenuIndex--;
        }
    }

    if(GetAsyncKeyState(VK_DOWN)&1)
    {
        if(MenuIndex < MAX_MENU_ITEMS-1)
        {
            MenuIndex++;
        }
    }

    if(GetAsyncKeyState(VK_END)&1)
    {
        hack[MenuIndex].on = !hack[MenuIndex].on;
        if(MenuIndex == NO_RECOIL)
        {
            //this is where we write memory, these are nop values
        }
        if(MenuIndex == UNLIM_AMMO)
        {
            //this is where we write memory
        }
    }

    if(GetAsyncKeyState(VK_INSERT)&1)
    {
        //TEXT DOESNT CHANGE as the hack is either hidden or not
        //and if its hidden you cant tell the user to turn hack on(at least we wont)
        hack[HIDE_MENU].on = !hack[HIDE_MENU].on;
    }

}

d3d9.cpp
Code:
#include <windows.h>

#include "d3d9.h"
#include "main.h"

tDirect3DCreate9 oDirect3DCreate9;

IDirect3D9 *APIENTRY hkDirect3DCreate9(UINT SDKVersion)
{
    IDirect3D9 *d3dint = oDirect3DCreate9(SDKVersion);

    if( d3dint != NULL )
    {
        hkIDirect3D9 *ret = new hkIDirect3D9(&d3dint);
    }
    else

    return d3dint;
}

d3d9.h
Code:
#ifndef _D3D9_H
#define _D3D9_H

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

#include <d3d9.h>
#include <d3dx9.h>
#include "d3d9int.h"
#include "d3d9dev.h"
#include "d3d9tex.h"

typedef IDirect3D9 *(APIENTRY *tDirect3DCreate9)(UINT);
extern tDirect3DCreate9 oDirect3DCreate9;

IDirect3D9 *APIENTRY hkDirect3DCreate9(UINT SDKVersion);

#endif

main.h
Code:
#define WIN32_LEAN_AND_MEAN

#ifndef _MAIN_H
#define _MAIN_H

//char *GetDirectoryFile(char *filename);
//void __cdecl add_log (const char * fmt, ...);
void *DetourFunc(BYTE *src, const BYTE *dst, const int len);
bool RetourFunc(BYTE *src, BYTE *restore, const int len);



#endif

main.cpp
Code:
#include <windows.h>
#include <fstream>
#include <stdio.h>
using namespace std;

#include "main.h"
#include "d3d9.h"

//Globals
ofstream ofile;   
char dlldir[320];

bool WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved)
{
    if(dwReason == DLL_PROCESS_ATTACH)
    {
        DisableThreadLibraryCalls(hDll);
        HMODULE hMod = LoadLibrary("d3d9.dll");       
   
        oDirect3DCreate9 = (tDirect3DCreate9)DetourFunc(
            (BYTE*)GetProcAddress(hMod, "Direct3DCreate9"),
            (BYTE*)hkDirect3DCreate9,
            5);

        return true;
    }

    return false;
}
/*
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
    BYTE *jmp = (BYTE*)malloc(len+5);
    DWORD dwback;

    VirtualProtect(src, len, PAGE_READWRITE, &dwback);

    memcpy(jmp, src, len);    jmp += len;
   
    jmp[0] = 0xE9;
    *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;

    src[0] = 0xE9;
    *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;

    VirtualProtect(src, len, dwback, &dwback);

    return (jmp-len);
}
*/
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
    BYTE *jmp = (BYTE*)malloc(len+5);
    DWORD dwback;

    VirtualProtect(jmp, len+5, PAGE_EXECUTE_READWRITE, &dwback); //This is the addition needed for Windows 7 RC

    VirtualProtect(src, len, PAGE_READWRITE, &dwback);

    memcpy(jmp, src, len);    jmp += len;
   
    jmp[0] = 0xE9;
    *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;

    src[0] = 0xE9;
    *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;

    VirtualProtect(src, len, dwback, &dwback);

    return (jmp-len);
}


bool RetourFunc(BYTE *src, BYTE *restore, const int len)
{
    DWORD dwback;
       
    if(!VirtualProtect(src, len, PAGE_READWRITE, &dwback))    { return false; }
    if(!memcpy(src, restore, len))                            { return false; }

    restore[0] = 0xE9;
    *(DWORD*)(restore+1) = (DWORD)(src - restore) - 5;

    if(!VirtualProtect(src, len, dwback, &dwback))            { return false; }
   
    return true;
}

Other Requirements:
[You must be registered and logged in to see this link.]

Learn in C++
Code:
#define ADDR_CLOSE 0x3772
void start()
{
while(1)
{
if (GetKeysState(VK_Esc) <0)
{           
*(DWORD*)ADDR_CLOSE = true;
}
Sleep(1)
}
}

Back to top Go down
View user profile http://phcreed.forumeiros.com
 
DIRECTX HACK CODE
Back to top 
Page 1 of 1
 Similar topics
-
» Building setback??

Permissions in this forum:You cannot reply to topics in this forum
PHCreed :: Programming :: C++-
Jump to: