QuestionHooking DX9 Present & Reset

Posts 1–2 of 2 · Page 1 of 1
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
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
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?