// dllmain.cpp : Defines the entry point for the DLL application. #include "framework.h" //#include "imgui.h" #include "imgui_impl_dx9.h" #include "imgui_impl_win32.h" typedef HRESULT ( __stdcall * _EndScene ) ( IDirect3DDevice9 * pDevice ) ; _EndScene oEndScene ; const char * windowName = "GTA: San Andreas" ; HWND window = FindWindowA ( NULL , windowName ) ; IDirect3DDevice9 * pDevice ; bool initialized = false ; void InitImGui ( IDirect3DDevice9 * pDevice ) { D3DDEVICE_CREATION_PARAMETERS CP ; pDevice -> GetCreationParameters ( & CP ) ; //hWnd = CP.hFocusWindow; ImGuiIO & io = ImGui :: GetIO ( ) ; ( void ) io ; io . IniFilename = NULL ; io . ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard ; io . Fonts -> AddFontDefault ( ) ; ImGui_ImplWin32_Init ( window ) ; ImGui_ImplDX9_Init ( pDevice ) ; initialized = true ; return ; } HRESULT __stdcall hkEndScene ( IDirect3DDevice9 * pDevice ) { if ( ! initialized ) InitImGui ( pDevice ) ; else { ImGui_ImplDX9_NewFrame ( ) ; ImGui_ImplWin32_NewFrame ( ) ; ImGui :: NewFrame ( ) ; //ImGui::ShowDemoWindow(&bShow); ImGui :: EndFrame ( ) ; ImGui :: Render ( ) ; ImGui_ImplDX9_RenderDrawData ( ImGui :: GetDrawData ( ) ) ; } return oEndScene ( pDevice ) ; } DWORD APIENTRY MainThread ( LPVOID lparam ) { while ( ! GetModuleHandleA ( "d3d9.dll" ) ) //waiting till d3d9.dll gets loaded { Sleep ( 1 ) ; } // Endscene hook void * * vTableDevice = * ( void * * * ) ( * ( DWORD * ) 0xC97C28 ) ; VTableHookManager * vmtHooks = new VTableHookManager ( vTableDevice , 119 ) ; oEndScene = ( _EndScene ) vmtHooks -> Hook ( 42 , ( void * ) hkEndScene ) ; //////////////////////////////////////////////////////////////////////////////// return false ; } BOOL APIENTRY DllMain ( HMODULE hModule , DWORD ul_reason_for_call , LPVOID lpReserved ) { switch ( ul_reason_for_call ) { case DLL_PROCESS_ATTACH : CreateThread ( 0 , 0 , MainThread , hModule , 0 , 0 ) ; case DLL_THREAD_ATTACH : case DLL_THREAD_DETACH : case DLL_PROCESS_DETACH : break ; } return TRUE ; }