Advertisement
Guest User

Untitled

a guest
Jul 9th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.33 KB | None | 0 0
  1. void DrawRect(LPDIRECT3DDEVICE9 Device_t, int X, int Y, int L, int H, D3DCOLOR color)
  2. {
  3.     D3DRECT rect = { X, Y, X + L, Y + H };
  4.     Device_t->Clear(1, &rect, D3DCLEAR_TARGET, color, 0, 0);
  5. }
  6.  
  7. typedef HRESULT(__stdcall *tPresent)(IDirect3DDevice9 *, CONST RECT *, CONST RECT *, HWND, CONST RGNDATA *);
  8. typedef HRESULT(__stdcall *tReset)(IDirect3DDevice9 *, D3DPRESENT_PARAMETERS *);
  9.  
  10. tReset                    gOriginalReset = nullptr;
  11. tPresent                gOriginalPresent = nullptr;
  12. D3DPRESENT_PARAMETERS*    gPresentParams = nullptr;
  13.  
  14. void CalcScreenCoors(CVector * vecWorld, CVector * vecScreen)
  15. {
  16.  
  17.  
  18.  
  19.     D3DXMATRIX m((float*)(0xB6FA2C));
  20.  
  21.  
  22.     DWORD *dwLenX = (DWORD*)(0xC17044);
  23.     DWORD *dwLenY = (DWORD*)(0xC17048);
  24.  
  25.  
  26.     vecScreen->fX = vecWorld->fZ * m._31 + vecWorld->fY * m._21 + vecWorld->fX * m._11 + m._41;
  27.     vecScreen->fY = vecWorld->fZ * m._32 + vecWorld->fY * m._22 + vecWorld->fX * m._12 + m._42;
  28.     vecScreen->fZ = vecWorld->fZ * m._33 + vecWorld->fY * m._23 + vecWorld->fX * m._13 + m._43;
  29.  
  30.  
  31.  
  32.     float fRecip = 1.0f / vecScreen->fZ;
  33.     vecScreen->fX *= fRecip * (*dwLenX);
  34.     vecScreen->fY *= fRecip * (*dwLenY);
  35. }
  36. CVector screen = {};
  37. HRESULT __stdcall hkdReset(IDirect3DDevice9 *d3dDev, D3DPRESENT_PARAMETERS *presentParams)
  38. {
  39.  
  40.     HRESULT hRes = gOriginalReset(d3dDev, presentParams);
  41.  
  42.     return hRes;
  43. }
  44.  
  45. HRESULT __stdcall hkdPresent(IDirect3DDevice9 *d3dDev, CONST RECT *srcRect, CONST RECT *destRect, HWND destWindow, CONST RGNDATA *dirtyRegion)
  46. {
  47.     DrawRect(d3dDev, (int)screen.fX - 5, (int)screen.fY + 5, 20, 10, D3DCOLOR_ARGB(200, 50, 50, 255));
  48.     HRESULT hRes = gOriginalPresent(d3dDev, srcRect, destRect, destWindow, dirtyRegion);
  49.  
  50.     return hRes;
  51. }
  52.  
  53. DWORD FindDevice(DWORD dwLen)
  54. {
  55.     DWORD dwObjBase = (DWORD)LoadLibraryA("d3d9.dll");
  56.  
  57.     if (dwObjBase == 0x0)
  58.         return 0x0;
  59.  
  60.     while (dwObjBase++ < dwObjBase + dwLen)
  61.     {
  62.         if ((*(WORD*)(dwObjBase + 0x00)) == 0x06C7 && (*(WORD*)(dwObjBase + 0x06)) == 0x8689 && (*(WORD*)(dwObjBase + 0x0C)) == 0x8689)
  63.         {
  64.             dwObjBase += 2;
  65.             break;
  66.         }
  67.     }
  68.  
  69.     return dwObjBase;
  70. };
  71.  
  72. bool initD3DRes()
  73. {
  74.     DWORD* VTable;
  75.     *(DWORD*)&VTable = *(DWORD *)FindDevice(0x128000);
  76.  
  77.     DWORD VP16, VP17;
  78.  
  79.     VirtualProtect((LPVOID)&VTable[16], 4, PAGE_READWRITE, &VP16);
  80.     VirtualProtect((LPVOID)&VTable[17], 4, PAGE_READWRITE, &VP17);
  81.  
  82.     gOriginalReset = (tReset)VTable[16];
  83.     gOriginalPresent = (tPresent)VTable[17];
  84.  
  85.     VTable[16] = (DWORD)hkdReset;
  86.     VTable[17] = (DWORD)hkdPresent;
  87.  
  88.     VirtualProtect((LPVOID)&VTable[16], 4, VP16, &VP16);
  89.     VirtualProtect((LPVOID)&VTable[17], 4, VP17, &VP17);
  90.  
  91.     return true;
  92. }
  93.  
  94. void destD3DRes()
  95. {
  96.     DWORD* VTable;
  97.     *(DWORD*)&VTable = *(DWORD*)FindDevice(0x128000);
  98.  
  99.     DWORD VP16, VP17;
  100.  
  101.     VirtualProtect((LPVOID)&VTable[16], 4, PAGE_READWRITE, &VP16);
  102.     VirtualProtect((LPVOID)&VTable[17], 4, PAGE_READWRITE, &VP17);
  103.  
  104.     VTable[16] = (DWORD)gOriginalReset;
  105.     VTable[17] = (DWORD)gOriginalPresent;
  106.  
  107.     VirtualProtect((LPVOID)&VTable[16], 4, VP16, &VP16);
  108.     VirtualProtect((LPVOID)&VTable[17], 4, VP17, &VP17);
  109. }
  110.  
  111. BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpvReserved)
  112. {
  113.  
  114.     if (dwReason == DLL_PROCESS_ATTACH)
  115.     {
  116.         DisableThreadLibraryCalls(hModule);
  117.         CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&hkdPresent, NULL, NULL, NULL);
  118.     }
  119.     else if (dwReason == DLL_PROCESS_DETACH) {
  120.     }
  121.     return TRUE;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement