Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cBase.h"
- #include "cDetour.h"
- #include "cMenu.h"
- #include "cHacks.h"
- #include "cSound.h"
- #include "cGuid.h"
- #include "cCrypt.h"
- #include "cPatch.h"
- #include <iostream>
- #include <fstream>
- #define D3DparamX , UINT paramx
- #define D3DparamvalX , paramx
- #pragma comment(lib, "d3d9.lib")
- #pragma comment(lib, "d3dx9.lib")
- using namespace std;
- cDetour *Detour;
- cBase Base;
- cMenu Menu;
- copt opt;
- cHacks Hacks;
- cSound Sound;
- cCrypt Crypt;
- LPDIRECT3DTEXTURE9 texGreen, texOrange, texCyan, texRed;
- bool Color = true;
- int Stridex = 0;
- int Numvertx = 0;
- int Primcountx = 0;
- int modelx = 0;
- int Strx = 0;
- int Numx = 0;
- int Primx = 0;
- static int incrementby = 1;
- void PreReset( LPDIRECT3DDEVICE9 pDevice )
- {
- // Code here
- Menu.PreReset();
- return;
- }
- void PostReset( LPDIRECT3DDEVICE9 pDevice )
- {
- // Code here
- Menu.PostReset(pDevice);
- return;
- }
- HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
- {
- if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)) )
- return E_FAIL;
- WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
- |(WORD)(((colour32>>20)&0xF)<<8)
- |(WORD)(((colour32>>12)&0xF)<<4)
- |(WORD)(((colour32>>4)&0xF)<<0);
- D3DLOCKED_RECT d3dlr;
- (*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
- WORD *pDst16 = (WORD*)d3dlr.pBits;
- for(int xy=0; xy < 8*8; xy++)
- *pDst16++ = colour16;
- (*ppD3Dtex)->UnlockRect(0);
- return S_OK;
- }
- typedef HRESULT ( WINAPI* oReset )( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters );
- oReset pReset;
- HRESULT APIENTRY myReset( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters )
- {
- _asm pushad;
- // Code here
- PreReset( pDevice );
- HRESULT hRet = pReset( pDevice, pPresentationParameters );
- if( SUCCEEDED( hRet ) )
- {
- PostReset( pDevice );
- }
- _asm popad;
- return hRet;
- }
- typedef HRESULT (WINAPI* oPresent) (LPDIRECT3DDEVICE9 pDevice, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND
- hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
- oPresent pPresent;
- HRESULT APIENTRY myPresent(LPDIRECT3DDEVICE9 pDevice, CONST RECT* pSourceRect,CONST RECT* pDestRect, HWND
- hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
- {
- _asm pushad;
- // Code here
- _asm popad;
- return pPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
- }
- typedef HRESULT ( WINAPI* oBeginScene )( LPDIRECT3DDEVICE9 pDevice );
- oBeginScene pBeginScene;
- HRESULT APIENTRY myBeginScene( LPDIRECT3DDEVICE9 pDevice )
- {
- _asm pushad;
- _asm popad;
- return pBeginScene( pDevice );
- }
- typedef HRESULT (WINAPI* oDrawIndexedPrimitive) (LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex,
- UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount);
- oDrawIndexedPrimitive pDrawIndexedPrimitive;
- HRESULT WINAPI myDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE pType D3DparamX ,UINT
- nMinIndex, UINT nNumVertices, UINT nStartIndex, UINT nPrimitiveCount )
- {
- _asm pushad;
- LPDIRECT3DVERTEXBUFFER9 Stream_Data;
- UINT Offset = 0;
- UINT Stride = 0;
- if(pDevice->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
- Stream_Data->Release();
- if(opt.logger.start){
- if(opt.legend.str){
- if(Stridex == Stride){
- pDevice->SetRenderState(D3DRS_ZENABLE, false);
- pDevice->SetTexture(0, texGreen);
- pDrawIndexedPrimitive(pDevice,pType D3DparamvalX,nMinIndex,nNumVertices,nStartIndex,nPrimitiveCount);
- pDevice->SetTexture(0, texGreen);
- pDevice->SetRenderState(D3DRS_ZENABLE, true);}}
- if(opt.legend.num){
- if(Numvertx == nNumVertices){
- pDevice->SetRenderState(D3DRS_ZENABLE, false);
- pDevice->SetTexture(0, texOrange);
- pDrawIndexedPrimitive(pDevice,pType D3DparamvalX,nMinIndex,nNumVertices,nStartIndex,nPrimitiveCount);
- pDevice->SetTexture(0, texOrange);
- pDevice->SetRenderState(D3DRS_ZENABLE, true);}}
- if(opt.legend.prim){
- if(Primcountx == nPrimitiveCount){
- pDevice->SetRenderState(D3DRS_ZENABLE, false);
- pDevice->SetTexture(0, texCyan);
- pDrawIndexedPrimitive(pDevice,pType D3DparamvalX,nMinIndex,nNumVertices,nStartIndex,nPrimitiveCount);
- pDevice->SetTexture(0, texCyan);
- pDevice->SetRenderState(D3DRS_ZENABLE, true);}}}
- _asm popad;
- return pDrawIndexedPrimitive(pDevice,pType D3DparamvalX,nMinIndex,nNumVertices,nStartIndex,nPrimitiveCount);
- }
- typedef HRESULT ( WINAPI* oEndScene )( LPDIRECT3DDEVICE9 pDevice );
- oEndScene pEndScene;
- HRESULT APIENTRY myEndScene( LPDIRECT3DDEVICE9 pDevice )
- {
- _asm pushad;
- PostReset(pDevice);
- Menu.ShowMenu(pDevice);
- PreReset(pDevice);
- if(Color){
- GenerateTexture(pDevice, &texGreen , D3DCOLOR_ARGB(255,0,255,0));
- GenerateTexture(pDevice, &texOrange , D3DCOLOR_ARGB(255,255,165,0));
- GenerateTexture(pDevice, &texCyan , D3DCOLOR_ARGB(255,0,255,255));
- GenerateTexture(pDevice, &texRed , D3DCOLOR_ARGB(255,255,0,0));
- Color = false;}
- if(opt.wire.str2){
- opt.wire.num2 = 0;
- opt.wire.prim2 = 0;
- if(GetAsyncKeyState(VK_PRIOR )&1) {Strx+=incrementby;}
- if(GetAsyncKeyState(VK_NEXT )&1) {Strx-=incrementby;}
- if(GetAsyncKeyState(VK_END )&1) {Strx = 0;}}
- if(opt.wire.num2){
- opt.wire.str2 = 0;
- opt.wire.prim2 = 0;
- if(GetAsyncKeyState(VK_PRIOR )&1) {Numx+=incrementby;}
- if(GetAsyncKeyState(VK_NEXT )&1) {Numx-=incrementby;}
- if(GetAsyncKeyState(VK_END )&1) {Numx = 0;}}
- if(opt.wire.prim2){
- opt.wire.str2 = 0;
- opt.wire.num2 = 0;
- if(GetAsyncKeyState(VK_PRIOR )&1) {Primx+=incrementby;}
- if(GetAsyncKeyState(VK_NEXT )&1) {Primx-=incrementby;}
- if(GetAsyncKeyState(VK_END )&1) {Primx = 0;}}
- if(opt.logger.hotkey){
- if(GetAsyncKeyState(VK_NUMPAD4)&1) {Stridex+=incrementby;
- opt.legend.str = 1;
- opt.legend.num = 0;
- opt.legend.prim = 0;}
- if(GetAsyncKeyState(VK_NUMPAD1)&1) {Stridex-=incrementby;
- opt.legend.str = 1;
- opt.legend.num = 0;
- opt.legend.prim = 0;}
- if(GetAsyncKeyState(VK_NUMPAD7)&1) Stridex = 0;
- if(GetAsyncKeyState(VK_NUMPAD5)&1) {Numvertx+=incrementby;
- opt.legend.str = 0;
- opt.legend.num = 1;
- opt.legend.prim = 0;}
- if(GetAsyncKeyState(VK_NUMPAD2)&1) {Numvertx-=incrementby;
- opt.legend.str = 0;
- opt.legend.num = 1;
- opt.legend.prim = 0;}
- if(GetAsyncKeyState(VK_NUMPAD8)&1) {Numvertx = 0;}
- if(GetAsyncKeyState(VK_NUMPAD6)&1) {Primcountx+=incrementby;
- opt.legend.str = 0;
- opt.legend.num = 0;
- opt.legend.prim = 1;}
- if(GetAsyncKeyState(VK_NUMPAD3)&1) {Primcountx-=incrementby;
- opt.legend.str = 0;
- opt.legend.num = 0;
- opt.legend.prim = 1;}
- if(GetAsyncKeyState(VK_NUMPAD9)&1) {Primcountx = 0;}
- if(GetAsyncKeyState(VK_SUBTRACT)&1){
- Stridex = 0;
- Numvertx = 0;
- Primcountx = 0;}}
- if(opt.logger.log){
- if(GetAsyncKeyState(VK_ADD)&1){
- modelx +=1;
- Base.WriteFile(Base.LOG,"_______Model Recognition________");
- Base.WriteFile(Base.LOG,"_________Texture_Mode__________");
- Base.WriteFile(Base.LOG,"Model: %d", modelx);
- Base.WriteFile(Base.LOG,"Stride: %d", Stridex);
- Base.WriteFile(Base.LOG,"Numvert: %d", Numvertx);
- Base.WriteFile(Base.LOG,"Primcount: %d", Primcountx);
- Base.WriteFile(Base.LOG,"_______________________________");}}
- opt.logger.main = 1;
- opt.info.main = 1;
- opt.options.main = 1;
- _asm popad;
- return pEndScene( pDevice );
- }
- template <typename C,typename VF >
- DWORD* VirtualFuncResolver(C obj, VF fun)
- {
- DWORD ofs_vfun = (DWORD)(((*(DWORD***)((DWORD*)((DWORD)*(DWORD**)&fun + 0x8)))));
- if(ofs_vfun>=0xA0000000)ofs_vfun = ofs_vfun & 0xFF;
- DWORD adr_obj = (DWORD)(**(DWORD****)&obj);
- DWORD* ENTRY = (DWORD*)(*(DWORD**)(adr_obj+ofs_vfun));
- return ENTRY;
- }
- DWORD* FindDevice(DWORD Base) // Credits to Croner at WarHax.com Simple Pattern Scan Function
- {
- for(long i= 0,n = 0; i < 0x128000; i++ )
- {
- if(*(BYTE *)(Base+i+0x00)==0xC7)n++;
- if(*(BYTE *)(Base+i+0x01)==0x06)n++;
- if(*(BYTE *)(Base+i+0x06)==0x89)n++;
- if(*(BYTE *)(Base+i+0x07)==0x86)n++;
- if(*(BYTE *)(Base+i+0x0C)==0x89)n++;
- if(*(BYTE *)(Base+i+0x0D)==0x86)n++;
- if(n == 6) return (DWORD*)
- (Base + i + 2);n = 0;
- }
- return(0);
- }
- typedef HRESULT ( WINAPI* oSetTransform ) (LPDIRECT3DDEVICE9 pDevice, D3DTRANSFORMSTATETYPE State, CONST
- D3DMATRIX* pMatrix);
- oSetTransform pSetTransform;
- HRESULT WINAPI mySetTransform(LPDIRECT3DDEVICE9 pDevice, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix)
- {
- // Code Here
- return pSetTransform(pDevice, State, pMatrix);
- }
- int iDIRECT3D(void)
- {
- HMODULE hD3D = NULL;
- do
- {
- hD3D = GetModuleHandle("d3d9.dll");
- Sleep(100);
- }
- while(!hD3D);
- DWORD_PTR * pDevice = FindDevice((DWORD)hD3D);
- DWORD_PTR * Vtable = 0;
- *(DWORD_PTR *)&Vtable = *(DWORD_PTR *)pDevice;
- // pReset = (oReset) Detour->Create
- ((PBYTE)VirtualFuncResolver(pDevice, &IDirect3DDevice9::Reset),(PBYTE)myReset,6);
- // pPresent = (oPresent) Detour->Create((PBYTE)
- VirtualFuncResolver(pDevice, &IDirect3DDevice9::Present),(PBYTE)myPresent,6);
- // pBeginScene = (oBeginScene) Detour->Create((PBYTE)
- VirtualFuncResolver(pDevice, &IDirect3DDevice9::BeginScene),(PBYTE)myBeginScene,6);
- pEndScene = (oEndScene) Detour->Create
- ((PBYTE)VirtualFuncResolver(pDevice, &IDirect3DDevice9::EndScene),(PBYTE)myEndScene,DETOUR_TYPE_OBS_XOR);// this works
- fine :)
- pDrawIndexedPrimitive = (oDrawIndexedPrimitive) Detour->Create((PBYTE)VirtualFuncResolver(pDevice,
- &IDirect3DDevice9::DrawIndexedPrimitive), (PBYTE)myDrawIndexedPrimitive,DETOUR_TYPE_OBS_XOR );
- pSetTransform = (oSetTransform) Detour->Create((PBYTE)Vtable[37],
- (PBYTE)mySetTransform,DETOUR_TYPE_OBS_XOR);
- return 0;
- }
- char* cBase::GetFile(char *file)
- {
- static char path[320];
- for(int i= 0;i<strlen(path);i++)
- path[i]=0;
- strcpy(path, Base.dllpath);
- strcat(path, file);
- return path;
- }
- void HackThread(void)
- {
- Hacks.HackThread();
- }
- void cBase::WriteFile(FILE *file,const char *fmt, ...)
- {
- char buffer[225] = "";
- va_list va_alist;
- va_start (va_alist, fmt);
- _vsnprintf (buffer,sizeof(buffer), fmt, va_alist);
- fprintf(file,buffer);
- fprintf(file,"\n");
- fflush(file);
- va_end (va_alist);
- }
- BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved){
- switch(dwReason)
- {
- case DLL_PROCESS_ATTACH:
- CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)iDIRECT3D, NULL, NULL, NULL);
- //CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)HackThread, NULL, NULL, NULL);
- // Get Dll Location
- GetModuleFileName(hDll,Base.dllpath,512);
- for(int i = strlen(Base.dllpath);i > 0; i--)
- {
- if(Base.dllpath[i] == '\\')
- {
- Base.dllpath[i+1] = 0; break;
- }
- }
- // Get Log File Location and Store into Class
- strcpy(Base.dllpath,Base.dllpath);
- strcpy(Base.logfile,Base.GetFile("Model_Rec_Log.txt"));
- Base.LOG = fopen(Base.logfile,"w");
- // Basic Status Messages
- break;
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
Add Comment
Please, Sign In to add comment