Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <d3d9.h>
- #include "../LIB/MinHook/include/MinHook.h"
- #include "../LIB/DXSDK/d3dx9.h"
- #pragma comment(lib, "d3d9.lib")
- #pragma comment(lib, "winmm.lib")
- #if defined _M_X64
- #pragma comment(lib, "../LIB/DXSDK/x64/d3dx9.lib")
- #elif defined _M_IX86
- #pragma comment(lib, "../LIB/DXSDK/x86/d3dx9.lib")
- #endif
- using namespace std;
- typedef HRESULT(APIENTRY *SetStreamSource_t)(IDirect3DDevice9*, UINT, IDirect3DVertexBuffer9*, UINT, UINT);
- SetStreamSource_t SetStreamSource_orig = 0;
- typedef HRESULT(APIENTRY *SetTexture_t)(IDirect3DDevice9*, DWORD, IDirect3DBaseTexture9 *);
- SetTexture_t SetTexture_orig = 0;
- typedef HRESULT(APIENTRY* Present_t) (IDirect3DDevice9*, const RECT *, const RECT *, HWND, const RGNDATA *);
- Present_t Present_orig = 0;
- typedef HRESULT(APIENTRY *Reset_t)(IDirect3DDevice9*, D3DPRESENT_PARAMETERS*);
- Reset_t Reset_orig = 0;
- HRESULT APIENTRY SetStreamSource_hook(LPDIRECT3DDEVICE9 pDevice, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT sStride)
- {
- return SetStreamSource_orig(pDevice, StreamNumber, pStreamData, OffsetInBytes, sStride);
- }
- HRESULT APIENTRY SetTexture_hook(LPDIRECT3DDEVICE9 pDevice, DWORD Sampler, IDirect3DBaseTexture9 *pTexture)
- {
- return SetTexture_orig(pDevice, Sampler, pTexture);
- }
- HRESULT APIENTRY Present_hook(LPDIRECT3DDEVICE9 pDevice, const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion)
- {
- return Present_orig(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
- }
- HRESULT APIENTRY Reset_hook(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS *pPresentationParameters)
- {
- HRESULT ResetReturn = Reset_orig(pDevice, pPresentationParameters);
- return ResetReturn;
- }
- DWORD WINAPI N7D3D(LPVOID lpParameter)
- {
- beforehook();
- HMODULE dDll = NULL;
- while (!dDll)
- {
- dDll = GetModuleHandleA("d3d9.dll");
- Sleep(100);
- }
- CloseHandle(dDll);
- IDirect3D9* d3d = NULL;
- IDirect3DDevice9* d3ddev = NULL;
- HWND tmpWnd = CreateWindowA("BUTTON", "DX", WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, HMODULE(), NULL);
- if (tmpWnd == NULL)
- {
- return 0;
- }
- d3d = Direct3DCreate9(D3D_SDK_VERSION);
- if (d3d == NULL)
- {
- DestroyWindow(tmpWnd);
- return 0;
- }
- D3DPRESENT_PARAMETERS d3dpp;
- ZeroMemory(&d3dpp, sizeof(d3dpp));
- d3dpp.Windowed = TRUE;
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.hDeviceWindow = tmpWnd;
- d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
- HRESULT result = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, tmpWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
- if (result != D3D_OK)
- {
- d3d->Release();
- DestroyWindow(tmpWnd);
- return 0;
- }
- #if defined _M_X64
- DWORD64* dVtable = (DWORD64*)d3ddev;
- dVtable = (DWORD64*)dVtable[0];
- #elif defined _M_IX86
- DWORD* dVtable = (DWORD*)d3ddev;
- dVtable = (DWORD*)dVtable[0];
- #endif
- if (MH_Initialize() != MH_OK) { return 1; }
- if (MH_CreateHook((DWORD_PTR*)dVtable[17], &Present_hook, reinterpret_cast<void**>(&Present_orig)) != MH_OK) { return 1; }
- if (MH_EnableHook((DWORD_PTR*)dVtable[17]) != MH_OK) { return 1; }
- if (MH_CreateHook((DWORD_PTR*)dVtable[100], &SetStreamSource_hook, reinterpret_cast<void**>(&SetStreamSource_orig)) != MH_OK) { return 1; }
- if (MH_EnableHook((DWORD_PTR*)dVtable[100]) != MH_OK) { return 1; }
- if (MH_CreateHook((DWORD_PTR*)dVtable[65], &SetTexture_hook, reinterpret_cast<void**>(&SetTexture_orig)) != MH_OK) { return 1; }
- if (MH_EnableHook((DWORD_PTR*)dVtable[65]) != MH_OK) { return 1; }
- if (MH_CreateHook((DWORD_PTR*)dVtable[16], &Reset_hook, reinterpret_cast<void**>(&Reset_orig)) != MH_OK) { return 1; }
- if (MH_EnableHook((DWORD_PTR*)dVtable[16]) != MH_OK) { return 1; }
- d3ddev->Release();
- d3d->Release();
- DestroyWindow(tmpWnd);
- return 1;
- }
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- if (ul_reason_for_call == 1) {
- DisableThreadLibraryCalls(hModule);
- CreateThread(0, 0, N7D3D, 0, 0, 0);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment