CasualGamer

Internal Hack Menu

Apr 15th, 2020
6,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.17 KB | None | 0 0
  1. // dllmain.cpp : Defines the entry point for the DLL application.
  2. #include "pch.h"
  3.  
  4. #include <iostream>
  5.  
  6. #include <d3d9.h>
  7. #include <d3dx9.h>
  8.  
  9. #pragma comment(lib, "d3d9.lib")
  10. #pragma comment(lib, "d3dx9.lib")
  11.  
  12. #include "detours.h"
  13. #pragma comment(lib, "detours.lib")
  14.  
  15.  
  16. HINSTANCE DllHandle;
  17.  
  18. typedef HRESULT(__stdcall* endScene)(IDirect3DDevice9* pDevice);
  19. endScene pEndScene;
  20.  
  21. LPD3DXFONT font;
  22.  
  23. HRESULT __stdcall hookedEndScene(IDirect3DDevice9* pDevice) {
  24.     //now here we can create our own graphics
  25.     int padding = 2;
  26.     int rectx1 = 100, rectx2 = 300, recty1 = 50, recty2 = 100;
  27.     D3DRECT rectangle = { rectx1, recty1, rectx2, recty2 };
  28.     pDevice->Clear(1, &rectangle, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 0.0f, 0); // this draws a rectangle
  29.     if (!font)
  30.         D3DXCreateFont(pDevice, 16, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &font);
  31.     RECT textRectangle;
  32.     SetRect(&textRectangle, rectx1 + padding, recty1 + padding, rectx2 - padding, recty2 - padding);
  33.     font->DrawText(NULL, "Press Numpad0 to Exit", -1, &textRectangle, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 153, 255, 153)); //draw text;
  34.     return pEndScene(pDevice); // call original endScene
  35. }
  36.  
  37. void hookEndScene() {
  38.     IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION); // create IDirect3D9 object
  39.     if (!pD3D)
  40.         return;
  41.  
  42.     D3DPRESENT_PARAMETERS d3dparams = { 0 };
  43.     d3dparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
  44.     d3dparams.hDeviceWindow = GetForegroundWindow();
  45.     d3dparams.Windowed = true;
  46.  
  47.     IDirect3DDevice9* pDevice = nullptr;
  48.  
  49.     HRESULT result =  pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dparams.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dparams, &pDevice);
  50.     if (FAILED(result) || !pDevice) {
  51.         pD3D->Release();
  52.         return;
  53.     }
  54.     //if device creation worked out -> lets get the virtual table:
  55.     void** vTable = *reinterpret_cast<void***>(pDevice);
  56.  
  57.     //now detour:
  58.  
  59.     pEndScene = (endScene)DetourFunction((PBYTE)vTable[42],(PBYTE)hookedEndScene);
  60.  
  61.     pDevice->Release();
  62.     pD3D->Release();
  63. }
  64.  
  65.  
  66. DWORD __stdcall EjectThread(LPVOID lpParameter) {
  67.     Sleep(100);
  68.     FreeLibraryAndExitThread(DllHandle, 0);
  69.     return 0;
  70. }
  71.  
  72. DWORD WINAPI Menue(HINSTANCE hModule) {
  73.     AllocConsole();
  74.     FILE* fp;
  75.     freopen_s(&fp, "CONOUT$", "w", stdout); //sets cout to be used with our newly created console
  76.  
  77.     hookEndScene();
  78.  
  79.     while (true) {
  80.         Sleep(50);
  81.         if (GetAsyncKeyState(VK_NUMPAD0)) {
  82.             DetourRemove((PBYTE)pEndScene, (PBYTE)hookedEndScene); //unhook to avoid game crash
  83.             break;
  84.         }
  85.     }
  86.     std::cout << "ight imma head out" << std::endl;
  87.     Sleep(1000);
  88.     fclose(fp);
  89.     FreeConsole();
  90.     CreateThread(0, 0, EjectThread, 0, 0, 0);
  91.     return 0;
  92. }
  93.  
  94. BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call,LPVOID lpReserved)
  95. {
  96.     switch (ul_reason_for_call)
  97.     {
  98.     case DLL_PROCESS_ATTACH:
  99.         DllHandle = hModule;
  100.         CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Menue, NULL, 0, NULL);
  101.     case DLL_THREAD_ATTACH:
  102.     case DLL_THREAD_DETACH:
  103.     case DLL_PROCESS_DETACH:
  104.         break;
  105.     }
  106.     return TRUE;
  107. }
Add Comment
Please, Sign In to add comment