Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.87 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <tlhelp32.h>
  3. #include <shlwapi.h>
  4.  
  5. #include <d3d9.h>
  6. #include <d3dx9.h>
  7.  
  8.  
  9. #define WIN32_LEAN_AND_MEAN
  10. #define WIN32_EXTRA_LEAN
  11.  
  12. #pragma warning(disable:4482)
  13. #pragma warning(disable:4244)
  14. #pragma warning(disable:4996)
  15. #pragma comment(lib, "d3d9.lib")
  16. #pragma comment(lib, "d3dx9.lib")
  17. #define D3DparamX       , UINT paramx
  18. #define D3DparamvalX    , paramx
  19.  
  20. bool Match(const BYTE* pData, const BYTE* bMask, const char* szMask)
  21. {
  22.     for(;*szMask;++szMask,++pData,++bMask)
  23.         if(*szMask=='x' && *pData!=*bMask )
  24.             return false;
  25.     return (*szMask) == NULL;
  26. }
  27.  
  28. DWORD FindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask)
  29. {
  30.     for(DWORD i=0; i<dwLen; i++)
  31.         if(Match((BYTE*)(dwAddress + i), bMask, szMask))
  32.             return (DWORD)(dwAddress+i);
  33.     return 0;
  34. }
  35.  
  36. void MakeJMP(BYTE *pAddress, DWORD dwJumpTo, DWORD dwLen)
  37. {
  38.     DWORD dwOldProtect, dwBkup, dwRelAddr;
  39.     VirtualProtect(pAddress, dwLen, PAGE_EXECUTE_READWRITE, &dwOldProtect);
  40.     dwRelAddr = (DWORD) (dwJumpTo - (DWORD) pAddress) - 5;
  41.     *pAddress = 0xE9;
  42.     *((DWORD *)(pAddress + 0x1)) = dwRelAddr;
  43.     for(DWORD x = 0x5; x < dwLen; x++) *(pAddress + x) = 0x90;
  44.     VirtualProtect(pAddress, dwLen, dwOldProtect, &dwBkup);
  45.     return;
  46. }
  47.  
  48. DWORD retMyDIP;
  49.  
  50. #define sWeapon 36
  51. #define sMap 24
  52. #define sSkyWalls 28
  53. #define sBody 44
  54. #define sHead 40
  55.  
  56. bool bEnable = true;
  57. bool Generate = true;
  58.  
  59.  void FillRGB(float x, float y, float w, float h, DWORD color,LPDIRECT3DDEVICE9 pDevice)
  60. {
  61.     D3DRECT rec = { x, y, x + w, y + h };
  62.     pDevice->Clear(1, &rec, D3DCLEAR_TARGET, color, 0, 0);
  63. }
  64.  
  65. HRESULT PheonxTexture(LPDIRECT3DDEVICE9 pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
  66. {
  67.     if(FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)))
  68.     return E_FAIL;
  69.     WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
  70.     |(WORD)(((colour32>>20)&0xF)<<8)
  71.     |(WORD)(((colour32>>12)&0xF)<<4)
  72.     |(WORD)(((colour32>>4)&0xF)<<0);
  73.     D3DLOCKED_RECT d3dlr;
  74.     (*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
  75.     WORD *pDst16 = (WORD*)d3dlr.pBits;
  76.     for(int xy=0; xy < 8*8; xy++)
  77.     *pDst16++ = colour16;
  78.     (*ppD3Dtex)->UnlockRect(0);
  79.     return S_OK;
  80. }
  81.  
  82. LPDIRECT3DTEXTURE9 Red,Green;
  83. D3DCOLOR RED = D3DCOLOR_ARGB(255, 255, 0, 0);
  84. D3DCOLOR GREEN = D3DCOLOR_ARGB(255, 0, 255, 0);
  85.  
  86.  
  87. void D3Dfunktionen (LPDIRECT3DDEVICE9 pDevice)
  88. {
  89.  
  90.     IDirect3DVertexBuffer9* pStreamData = NULL;
  91.     UINT iOffsetInBytes,iStride;  
  92.     pDevice->GetStreamSource(0,&pStreamData,&iOffsetInBytes,&iStride);
  93.  
  94.          if (Generate)
  95.         {
  96.             PheonxTexture(pDevice, &Red, RED);
  97.             PheonxTexture(pDevice, &Green, GREEN);
  98.             Generate = false;
  99.         }
  100.  
  101.  
  102.     if(iStride == sBody || iStride == sHead || iStride == sWeapon)
  103.     {
  104.         pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
  105.     }
  106. }
  107.  
  108. __declspec(naked) HRESULT WINAPI MyDIP()
  109. {
  110.     static LPDIRECT3DDEVICE9 pDevice;
  111.  
  112.     __asm
  113.     {
  114.         MOV EDI,EDI
  115.         PUSH EBP
  116.         MOV EBP,ESP
  117.         MOV EAX,DWORD PTR SS:[EBP + 0x8]
  118.         MOV pDevice,EAX
  119.     }
  120.     if(GetAsyncKeyState(VK_INSERT)&1) bEnable = !bEnable;
  121.     if(bEnable){
  122.  
  123.          FillRGB(40, 40, 40, 40, RED, pDevice);
  124.     D3Dfunktionen(pDevice);
  125.     }
  126.  
  127.     __asm
  128.     {
  129.         JMP retMyDIP
  130.     }
  131. }
  132.  
  133. void Hook ()
  134. {
  135.     DWORD hD3D = (DWORD)LoadLibraryA("d3d9.dll");
  136.     DWORD *vtbl;
  137.     DWORD adr = FindPattern(hD3D, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
  138.     if(adr)
  139.     {
  140.         memcpy(&vtbl,(void*)(adr + 2),4);
  141.         retMyDIP = vtbl[147] + 0x5;
  142.         MakeJMP((PBYTE)vtbl[147],(DWORD)MyDIP,0x5);
  143.     }
  144. }
  145.  
  146. extern "C"
  147. {
  148.     BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  149.     {
  150.         switch (fdwReason)
  151.         {
  152.         case DLL_PROCESS_ATTACH:           
  153.             CreateThread(0,0,(LPTHREAD_START_ROUTINE)Hook,0,0,0);
  154.             //MessageBoxA(NULL,"","Injetou",0);
  155.             //HideModule(hinstDLL);
  156.             break;
  157.         }
  158.         return true;
  159.     }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement