Results 1 to 2 of 2
  1. #1
    exp111's Avatar
    Join Date
    Oct 2013
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0

    Question Hooking DX9 Present & Reset

    Hey,

    I've started now writing some stuff for MW2 and I now wanted to make a gui/ingame menu.
    As I like the ImGui menus (and have some menus already written for it) and wanted to use it here to.

    The problem is I just can't seem to get it working.
    I'm swapping the pointer to the original present/reset to my own functions (in the gameoverlayrenderer.dll) but they don't seem to get called.

    My code to swap them (should work for all dx9 games):
    Code:
    Hooks::present_addr = FindPattern("gameoverlayrenderer.dll", Signatures::Present) + 2;
    Hooks::reset_addr = FindPattern("gameoverlayrenderer.dll", Signatures::Reset) + 2;
    
    Hooks::original_present = **reinterpret_cast<decltype(&Hooks::original_present)*>(Hooks::present_addr);
    Hooks::original_reset = **reinterpret_cast<decltype(&Hooks::original_reset)*>(Hooks::reset_addr);
    
    **reinterpret_cast<void***>(Hooks::present_addr) = reinterpret_cast<void*>(&Hooks::user_present);
    **reinterpret_cast<void***>(Hooks::reset_addr) = reinterpret_cast<void*>(&Hooks::user_reset);
    The original functions addresses are found but it doesn't get called. It's weird as the Steam overlay works fine

    Did anyone get it an ImGui menu working? Appreciate any help

  2. #2
    moofmonkey's Avatar
    Join Date
    Dec 2017
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    1
    Sorry if late, but there's some info.
    1. Hook release in GameOverlayRenderer64.dll \x48\x89\x05\xCC\xCC\xCC\xCC\x48\x8D\x15\xCC\xCC\x CC\xCC\x48\x8B\x4B\x68 xxx????xxx????xxxx (x64 pattern for variable reference)
    2. Do things here: init WndProc, hook EndScene, etc.
    For me that code is... (comments aren't mine)
    Code:
    ULONG __stdcall hkRelease(IDirect3DDevice9* thisptr) {
    	// Perform general setup tasks when this function is called for the first time.
    	static bool is_initialized = false;
    	static bool init_running = false;
    
    	if (!is_initialized) {
    		while (init_running) Sleep(40);
    		if (is_initialized) goto skip;
    		init_running = true;
    
    		static HWND console_hwnd = GetConsoleHwnd();
    		EnumWindows([](HWND hwnd, LPARAM game_pid) -> BOOL {
    			// Skip windows not belonging to the game process.
    			DWORD hwnd_pid = NULL;
    
    			GetWindowThreadProcessId(hwnd, &hwnd_pid);
    
    			if (hwnd_pid != game_pid || hwnd == console_hwnd)
    				return TRUE;
    
    			// Set the target window handle and stop the callback.
    			game_hwnd = hwnd;
    
    			return FALSE;
    		}, GetCurrentProcessId());
    
    		if (game_hwnd != NULL) {
    			// Swap out the window message handler for our own, allowing us to intercept input events.
    			game_wndproc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(game_hwnd, GWLP_WNDPROC, LONG_PTR(hkWndProc)));
    			g_pRenderer = new Renderer(thisptr);
    			pOriginalRender = (HRESULT(__stdcall*)(IDirect3DDevice9*)) DetourPointer(pOriginalRender_Restore = *(void***)thisptr + 42, hkRender); // endscene
    
    			// Perform final ImGui setup tasks and..
    			ImGui_ImplDX9_Init(game_hwnd, thisptr);
    
    			// ..we're all done!
    			is_initialized = true;
    		}
    		init_running = false;
    		skip:;
    	}
    
    	return pOriginalRelease(thisptr);
    }
    3. ???
    4. PROFIT

  3. The Following User Says Thank You to moofmonkey For This Useful Post:

    exp111 (08-05-2018)

Similar Threads

  1. [Help] All hooks work, except for Reset (D3D9)
    By diesel3009 in forum DirectX/D3D Development
    Replies: 6
    Last Post: 07-28-2013, 03:52 PM
  2. [Source Code] Engine Hook - Reset, Present, BeginScene, EndScene and DrawIndexedPrimitive
    By [H]aaBX in forum Combat Arms EU Hack Coding/Source Code
    Replies: 3
    Last Post: 02-21-2013, 10:02 PM
  3. [Release] Hook Present Engine 6/9/2012
    By Avene in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 14
    Last Post: 09-06-2012, 10:58 PM
  4. [Release] Hook Present Engine
    By Avene in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 16
    Last Post: 09-05-2012, 06:14 PM
  5. [Request] Information about hooking present / reset
    By PgSQL in forum CrossFire Europe Hack Source Code
    Replies: 0
    Last Post: 08-14-2012, 05:13 PM