diff --git a/examples/example_dx12_hook/dllmain.cpp b/examples/example_dx12_hook/dllmain.cpp index 1e7101f..20c89a4 100644 --- a/examples/example_dx12_hook/dllmain.cpp +++ b/examples/example_dx12_hook/dllmain.cpp @@ -449,9 +449,8 @@ BOOL WINAPI DllMain(HINSTANCE h_instance, DWORD reason, LPVOID) if (reason == DLL_PROCESS_ATTACH) { DisableThreadLibraryCalls(h_instance); - CreateThread( - nullptr, 0, - [](LPVOID) -> DWORD + std::thread( + []() { while (!GetModuleHandle("d3d12.dll")) Sleep(100); @@ -462,8 +461,8 @@ BOOL WINAPI DllMain(HINSTANCE h_instance, DWORD reason, LPVOID) mgr.set_on_execute_command_lists(on_execute_command_lists); std::ignore = mgr.hook_dx12(); return 0; - }, - nullptr, 0, nullptr); + }) + .detach(); } else if (reason == DLL_PROCESS_DETACH) { diff --git a/examples/example_dx9_hook/dllmain.cpp b/examples/example_dx9_hook/dllmain.cpp index 5e4961b..fc21e30 100644 --- a/examples/example_dx9_hook/dllmain.cpp +++ b/examples/example_dx9_hook/dllmain.cpp @@ -1,16 +1,15 @@ +#include "omath/hooks/hooks_manager.hpp" #include #include #include #include #include -#include "omath/hooks/hooks_manager.hpp" - extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND, UINT, WPARAM, LPARAM); namespace { - bool g_initialized = false; + bool g_initialized = false; bool g_init_attempted = false; void init(IDirect3DDevice9* device) @@ -31,11 +30,13 @@ namespace ImGui_ImplDX9_Init(device); auto& mgr = omath::hooks::HooksManager::get(); - mgr.set_on_wnd_proc([](HWND h, UINT msg, WPARAM wp, LPARAM lp) -> std::optional { - if (ImGui_ImplWin32_WndProcHandler(h, msg, wp, lp)) - return 0; - return std::nullopt; - }); + mgr.set_on_wnd_proc( + [](HWND h, UINT msg, WPARAM wp, LPARAM lp) -> std::optional + { + if (ImGui_ImplWin32_WndProcHandler(h, msg, wp, lp)) + return 0; + return std::nullopt; + }); std::ignore = mgr.hook_wnd_proc(params.hFocusWindow); g_initialized = true; @@ -54,11 +55,8 @@ namespace ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - ImGui::SetNextWindowSize({300.f, 80.f}, ImGuiCond_Once); - ImGui::SetNextWindowPos({10.f, 10.f}, ImGuiCond_Once); - ImGui::Begin("omath | DX9 hook"); - ImGui::Text("Hook active"); - ImGui::Text("FPS: %.1f", ImGui::GetIO().Framerate); + ImGui::GetIO().MouseDrawCursor = true; + ImGui::ShowDemoWindow(); ImGui::End(); ImGui::EndFrame(); @@ -78,17 +76,19 @@ BOOL WINAPI DllMain(HINSTANCE h_instance, DWORD reason, LPVOID) if (reason == DLL_PROCESS_ATTACH) { DisableThreadLibraryCalls(h_instance); - CreateThread(nullptr, 0, [](LPVOID) -> DWORD - { - while (!GetModuleHandle("d3d9.dll")) - Sleep(100); + std::thread( + []() + { + while (!GetModuleHandle("d3d9.dll")) + Sleep(100); - auto& mgr = omath::hooks::HooksManager::get(); - mgr.set_on_dx9_present(on_present); - mgr.set_on_dx9_reset(on_reset); - std::ignore = mgr.hook_dx9(); - return 0; - }, nullptr, 0, nullptr); + auto& mgr = omath::hooks::HooksManager::get(); + mgr.set_on_dx9_present(on_present); + mgr.set_on_dx9_reset(on_reset); + std::ignore = mgr.hook_dx9(); + return 0; + }) + .detach(); } else if (reason == DLL_PROCESS_DETACH) {