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