#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 1
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <string>
#include <assert.h>
#include <process.h>
#include <dinput.h>
#include <tchar.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#include "VMTHookManager.h"
WNDPROC oWndProc;
DWORD g_dwSAMP_Addr;
typedef HRESULT(WINAPI* _EndScene)(IDirect3DDevice9*); //прототип
_EndScene oEndScene; //экземпляр прототипа, для возврата оригинала
typedef HRESULT(WINAPI* _Present)(IDirect3DDevice9*, const RECT*, const RECT*, HWND, const RGNDATA*); //прототип
_Present oPresent; //экземпляр прототипа, для возврата оригинала
typedef HRESULT(WINAPI* _Reset)(IDirect3DDevice9*, D3DPRESENT_PARAMETERS*);
_Reset oReset;
void DrawRect(LPDIRECT3DDEVICE9 m_pDevice, int X, int Y, int L, int H, D3DCOLOR color)
{
D3DRECT rect = { X, Y, X + L, Y + H };
m_pDevice->Clear(1, &rect, D3DCLEAR_TARGET, color, 0, 0);
}
HRESULT WINAPI hooked_Present(IDirect3DDevice9* pDevice, const RECT* pSourceRect, const RECT* pDestRect, HWND hdest, const RGNDATA* pDirtyRegion)
{
DrawRect(pDevice, 250, 250, 10, 10, 0xFFFF0000);
return oPresent(pDevice, pSourceRect, pDestRect, hdest, pDirtyRegion); // возврат оригинала
}
HRESULT WINAPI myEndScene(IDirect3DDevice9* m_pDevice)
{
return oEndScene(m_pDevice);
}
HRESULT WINAPI myReset(IDirect3DDevice9* m_pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
{
auto result = oReset(m_pDevice, pPresentationParameters);
return result;
}
void InitHook()
{
void** vTableDevice = *(void***)(*(DWORD*)0xC97C28); // адрес Device
VMTHookManager* vmtHooks = new VMTHookManager(vTableDevice);
oPresent = (_Present)vmtHooks->Hook(17, (void*)hooked_Present);
oEndScene = (_EndScene)vmtHooks->Hook(42, (void*)myEndScene); // 42 - номер EndScene
oReset = (_Reset)vmtHooks->Hook(16, (void*)myReset);// 16 - номер Reset
}
int WINAPI Thread()
{
while (*(DWORD*)0xC8D4C0 != 9) // проверка на статус загрузки игры
Sleep(100);
InitHook();
return 0;
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Thread, NULL, NULL, NULL);
return TRUE;
}