Main.cpp
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////
// Base by Vitrix Maggot ////
/// :) ////
//////////////////////////////
#include <windows.h>
#include "Menu.h"
#include "Hacks.h"
#include <d3d9.h>
#pragma comment(lib, "d3d9.lib")
#include <d3dx9.h>
#pragma comment(lib, "d3dx9.lib")
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef HRESULT (WINAPI* zCreateDevice) (LPDIRECT3D9, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE9*);
typedef HRESULT (WINAPI* zEndScene) (LPDIRECT3DDEVICE9);
typedef HRESULT (WINAPI* zDIP) (LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
zCreateDevice OriginalCreateDevice = NULL;
zEndScene OriginalEndScene = NULL;
zDIP OriginalDIP = NULL;
HRESULT WINAPI Direct3DCreate9_VMTable (VOID);
HRESULT WINAPI CreateDevice_Hook (LPDIRECT3D9, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE9*);
HRESULT WINAPI EndScene_Hook (LPDIRECT3DDEVICE9);
HRESULT WINAPI DIP_Hook(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
DWORD WINAPI SetHooks(LPVOID);
DWORD* VMTable = NULL;
//////////////////////////////////////////////////////////////////
LPD3DXFONT D3DFont;
bool pFont;
D3DMENUINFO D3DInfo;
char* Options[] = { "[Off]", "[On]" };
int AutoKill, OneHit, MoveMenu, MPFull, InstantSpell;
/////////////////////////////////////////////////////////////////////
BOOL WINAPI DllMain(HINSTANCE hinstModule, DWORD dwReason, LPVOID lpvReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
D3DInfo.PosX = 30;
D3DInfo.PosY = 70;
D3DInfo.Posy = 60;
D3DInfo.Current = 1;
D3DInfo.Menu = 1;
DisableThreadLibraryCalls(hinstModule);
if(Direct3DCreate9_VMTable() == D3D_OK)
return TRUE;
}
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT WINAPI Direct3DCreate9_VMTable(VOID)
{
LPDIRECT3D9 Direct3D_Object = Direct3DCreate9(D3D_SDK_VERSION);
if(Direct3D_Object == NULL)
return D3DERR_INVALIDCALL;
VMTable = (PDWORD)*(DWORD*)Direct3D_Object;
Direct3D_Object->Release();
DWORD dwProtect;
if(VirtualProtect(&VMTable[16], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
{
*(DWORD*)&OriginalCreateDevice = VMTable[16];
*(DWORD*)&VMTable[16] = (DWORD)CreateDevice_Hook;
if(VirtualProtect(&VMTable[16], sizeof(DWORD), dwProtect, &dwProtect) == 0)
return D3DERR_INVALIDCALL;
}
else
return D3DERR_INVALIDCALL;
return D3D_OK;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT WINAPI CreateDevice_Hook(LPDIRECT3D9 Direct3D_Object, UINT Adapter, D3DDEVTYPE DeviceType, HWND FocusWindow,
DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* PresentationParameters,
LPDIRECT3DDEVICE9* Returned_Device_Interface)
{
HRESULT hRet = OriginalCreateDevice(Direct3D_Object, Adapter, DeviceType, FocusWindow, BehaviorFlags,
PresentationParameters, Returned_Device_Interface);
DWORD dwProtect;
if(VirtualProtect(&VMTable[16], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
{
*(DWORD*)&VMTable[16] = *(PDWORD)&OriginalCreateDevice;
OriginalCreateDevice = NULL;
if(VirtualProtect(&VMTable[16], sizeof(DWORD), dwProtect, &dwProtect) == 0)
return D3DERR_INVALIDCALL;
}
else return D3DERR_INVALIDCALL;
if(hRet == D3D_OK)
{
VMTable = (PDWORD)*(PDWORD)*Returned_Device_Interface;
*(DWORD*)&OriginalEndScene = (DWORD)VMTable[42];
*(DWORD*)&OriginalDIP = (DWORD)VMTable[82];
if(CreateThread(NULL, 0, SetHooks, NULL, 0, NULL) == NULL)
return D3DERR_INVALIDCALL;
}
return hRet;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT WINAPI EndScene_Hook(LPDIRECT3DDEVICE9 pDevice)
{
if (!(*(DWORD*)(zLoginStatus)))
{
if (!pFont)
{
D3DXCreateFontA(pDevice, 14, 0, 400, 1, 0, 1, 0, 4, 0 | (0<<4), "Arial Black", &D3DFont);
pFont = true;
}
if(GetAsyncKeyState(VK_INSERT) != 0) D3DInfo.Menu = !D3DInfo.Menu;
if (D3DInfo.Menu)
{
pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
DrawD3DBox(D3DInfo.PosX - 10, D3DInfo.PosY - 22, 162, 20, TBlack, TBlack, pDevice);
DrawD3DBorder(D3DInfo.PosX - 10, D3DInfo.PosY - 22, 162, 20, 1, TBlack, pDevice);
DrawD3DText(D3DFont, D3DInfo.PosX , D3DInfo.PosY - 20, Red, "GC4You V2.0");
DrawD3DText(D3DFont, D3DInfo.PosX + 100, D3DInfo.PosY - 20, Green, "12/12/12");
DrawD3DBox(D3DInfo.PosX - 10, D3DInfo.PosY, 162, 220, TBlack, TBlack, pDevice);
DrawD3DBorder(D3DInfo.PosX - 10, D3DInfo.PosY, 162, 220, 1, TBlack, pDevice);
DrawD3DBorder(D3DInfo.PosX - 10, D3DInfo.Posy + 2 + (D3DInfo.MenuSelection * 15), 162, 13, 1, Cyan, pDevice);
D3DInfo.Current = 1;
if(GetAsyncKeyState(VK_PRIOR)&1)
D3DInfo.MenuSelection--;
if(GetAsyncKeyState(VK_NEXT)&1)
D3DInfo.MenuSelection++;
AddD3DItem(&D3DInfo, "Move Menu", 1, MoveMenu, 0, Options, D3DFont);
AddD3DItem(&D3DInfo, "AutoKill", 1, AutoKill, 0, Options, D3DFont);
AddD3DItem(&D3DInfo, "OneHit", 1, OneHit, 0, Options, D3DFont);
AddD3DItem(&D3DInfo, "MP Full", 1, MPFull, 0, Options, D3DFont);
AddD3DItem(&D3DInfo, "Instant Spell", 1, InstantSpell, 0, Options, D3DFont);
if (MoveMenu)
{
POINT p;
GetCursorPos(&p);
D3DInfo.PosX = p.x;
D3DInfo.PosY = p.y;
D3DInfo.Posy = p.y - 10;
}
if (AutoKill)
szAutoKill;
if (OneHit)
szOneHit;
if (MPFull)
szMPFull;
if (InstantSpell)
szInstantSpell;
ShowCursor(!MoveMenu);
if(D3DInfo.MenuSelection >= D3DInfo.Current)
D3DInfo.MenuSelection = 1;
else if(D3DInfo.MenuSelection < 1)
D3DInfo.MenuSelection = D3DInfo.Current;
}
}
return OriginalEndScene(pDevice);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT WINAPI DIP_Hook(LPDIRECT3DDEVICE9 Device_Interface, D3DPRIMITIVETYPE Type, INT BaseIndex,
UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount)
{
LPDIRECT3DVERTEXBUFFER9 Stream_Data;
UINT Offset = 0;
UINT Stride = 0;
if(Device_Interface->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
Stream_Data->Release();
return OriginalDIP(Device_Interface, Type, BaseIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI SetHooks(LPVOID Param)
{
while(true)
{
Sleep(100);
*(DWORD*)&VMTable[42] = (DWORD)EndScene_Hook;
*(DWORD*)&VMTable[82] = (DWORD)DIP_Hook;
}
return 1;
}
Menu.h:
//Funcions by Vitrix Maggot
#include <windows.h>
#include <d3d9.h>
#pragma comment(lib, "d3d9.lib")
#include <d3dx9.h>
#pragma comment(lib, "d3dx9.lib")
#define Red D3DCOLOR_ARGB(255, 255, 000, 000)
#define Green D3DCOLOR_ARGB(255, 127, 255, 000)
#define Cyan D3DCOLOR_ARGB(255, 000, 255, 255)
#define TBlack D3DCOLOR_ARGB(128, 000, 000, 000)
struct D3DMENUINFO
{
int MenuSelection;
int PosX;
int PosY;
int Posy;
int Current;
bool Menu;
};
void DrawD3DText(LPD3DXFONT D3DFont, int x, int y, DWORD Color, char *Text)
{
RECT rect;
SetRect(&rect, x, y, x, y);
D3DFont->DrawTextA(NULL, Text, -1, &rect, DT_LEFT | DT_NOCLIP, Color);
}
void FillRGB(int x, int y, int w, int h, D3DCOLOR Color, LPDIRECT3DDEVICE9 pDevice)
{
D3DRECT rec = { x, y, x + w, y + h };
pDevice->Clear(1, &rec, D3DCLEAR_TARGET, Color, 0, 0);
}
void DrawD3DBorder(int x, int y, int w, int h, int px, D3DCOLOR BorderColor, LPDIRECT3DDEVICE9 pDevice)
{
FillRGB(x,(y + h - px), w, px, BorderColor, pDevice);
FillRGB(x, y, px, h, BorderColor, pDevice);
FillRGB(x, y, w, px, BorderColor, pDevice);
FillRGB(x + w - px, y, px, h, BorderColor, pDevice);
}
void DrawD3DBox(int x, int y, int w, int h, D3DCOLOR Color, D3DCOLOR BorderColor, LPDIRECT3DDEVICE9 pDevice)
{
DrawD3DBorder(x, y, w, h, 2, BorderColor, pDevice);
const DWORD D3D_FVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE;
struct Vertex {
float x, y, w, h;
D3DCOLOR Color;
}
V[4] = {{(float) x, (float)(y + h), 0.0f, 0.0f, Color},
{(float) x, (float)y, 0.0f, 0.0f, Color},
{(float)(x + w), (float)(y + h), 0.0f, 0.0f, Color},
{(float)(x + w), (float)y, 0.0f, 0.0f, Color}
};
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, D3DZB_TRUE);
pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
pDevice->SetRenderState(D3DRS_FOGENABLE, D3DZB_FALSE);
pDevice->SetFVF(D3D_FVF);
pDevice->SetTexture(0, NULL);
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, V, sizeof(Vertex));
}
void AddD3DCategory(void* MenuInf, char* Text, int Y, int Color, LPD3DXFONT pFont)
{
D3DMENUINFO MenuInfo;
memcpy(&MenuInfo, MenuInf, sizeof(MenuInfo));
DrawD3DText(pFont, MenuInfo.PosX + 25, MenuInfo.PosY + Y, Color, Text);
}
void AddD3DItem(void* MenuInf, char* Text, int MaxValue, int &Value, int Kind, char** Opt, LPD3DXFONT pFont)
{
D3DMENUINFO MenuInfo;
memcpy(&MenuInfo, MenuInf, sizeof(MenuInfo));
if(MenuInfo.Menu) {
if(MenuInfo.MenuSelection == MenuInfo.Current)
{
if(GetAsyncKeyState(VK_HOME)&1) {
if(Value < MaxValue)
{
Value++;
}
else
{
Value = 0;
}
}
}
if(MenuInfo.MenuSelection == MenuInfo.Current) {
DrawD3DText(pFont, MenuInfo.PosX - 5, MenuInfo.Posy + (MenuInfo.Current * 15), Cyan,Text);
DrawD3DText(pFont, MenuInfo.PosX + 120, MenuInfo.Posy + (MenuInfo.Current * 15), Cyan,Opt[Value]);
} else if(Value > 0) {
if(Kind == 1) {
} else {
DrawD3DText(pFont, MenuInfo.PosX - 5, MenuInfo.Posy + (MenuInfo.Current * 15), Green, Text);
DrawD3DText(pFont, MenuInfo.PosX + 120, MenuInfo.Posy + (MenuInfo.Current * 15), Green, Opt[Value]);
}
} else {
if(Kind == 1) {
} else {
DrawD3DText(pFont, MenuInfo.PosX - 5, MenuInfo.Posy + (MenuInfo.Current * 15), Red, Text);
DrawD3DText(pFont, MenuInfo.PosX + 120, MenuInfo.Posy + (MenuInfo.Current * 15), Red, Opt[Value]);
}
}
MenuInfo.Current++;
}
memcpy(MenuInf, &MenuInfo, sizeof(MenuInfo));
}