DWORD FindDevice(DWORD dwLen)
{
DWORD dwObjBase = (DWORD)LoadLibraryA("d3d9.dll");
if (dwObjBase == 0x0)
return 0x0;
while (dwObjBase++ < dwObjBase + dwLen)
{
if ((*(WORD*)(dwObjBase + 0x00)) == 0x06C7 && (*(WORD*)(dwObjBase + 0x06)) == 0x8689 && (*(WORD*)(dwObjBase + 0x0C)) == 0x8689)
{
dwObjBase += 2;
break;
}
}
return dwObjBase;
};
bool initD3DRes()
{
DWORD* VTable;
*(DWORD*)&VTable = *(DWORD *)FindDevice(0x128000);
DWORD VP16, VP17;
VirtualProtect((LPVOID)&VTable[16], 4, PAGE_READWRITE, &VP16);
VirtualProtect((LPVOID)&VTable[17], 4, PAGE_READWRITE, &VP17);
vars::oReset = (tReset)VTable[16];
vars::oPresent = (tPresent)VTable[17];
VTable[16] = (DWORD)hkReset;
VTable[17] = (DWORD)hkPresent;
VirtualProtect((LPVOID)&VTable[16], 4, VP16, &VP16);
VirtualProtect((LPVOID)&VTable[17], 4, VP17, &VP17);
return true;
}
void destD3DRes()
{
DWORD* VTable;
*(DWORD*)&VTable = *(DWORD*)FindDevice(0x128000);
DWORD VP16, VP17;
VirtualProtect((LPVOID)&VTable[16], 4, PAGE_READWRITE, &VP16);
VirtualProtect((LPVOID)&VTable[17], 4, PAGE_READWRITE, &VP17);
VTable[16] = (DWORD)vars::oReset;
VTable[17] = (DWORD)vars::oPresent;
VirtualProtect((LPVOID)&VTable[16], 4, VP16, &VP16);
VirtualProtect((LPVOID)&VTable[17], 4, VP17, &VP17);
}