|
2 | 2 |
|
3 | 3 | #include "game/core/core.h" |
4 | 4 | #include "gui/window/window.h" |
| 5 | +#include "gui/window/window_finder.h" |
| 6 | +#include "gui/window/external_overlay.h" |
| 7 | +#include "gui/window/input_forwarder.h" |
5 | 8 |
|
6 | 9 | static void Init(HMODULE hMod) |
7 | 10 | { |
@@ -42,23 +45,56 @@ static void Init(HMODULE hMod) |
42 | 45 |
|
43 | 46 | LOG_INFO(X("initializing Overlay Hook.")); |
44 | 47 |
|
45 | | - for (const auto& [method, name] : hookMethods) { |
46 | | - LOG_DEBUG(X("Trying {} DirectX Hook."), name); |
47 | | - if (dx_hook::Hk11::Build(Window::OnPresent, method)) { |
| 48 | + for (const auto& [method, name] : hookMethods) |
| 49 | + { |
| 50 | + if (dx_hook::Hk11::Build(Window::OnPresent, method)) |
| 51 | + { |
48 | 52 | LOG_INFO(X("Successfully initialized {} DirectX Hook."), name); |
49 | 53 | hookSuccess = true; |
50 | 54 | break; |
51 | 55 | } |
52 | | - |
53 | | - LOG_ERROR(X("Failed to initialize {} DirectX Hook."), name); |
54 | 56 | } |
55 | 57 |
|
56 | | - if (!hookSuccess) |
| 58 | + if (!hookSuccess) |
57 | 59 | { |
58 | | - LOG_ERROR(X("All hooking methods failed!")); |
59 | | - goto exit; |
| 60 | + HWND gameHwnd = nullptr; |
| 61 | + for (uint8_t i = 0; i < 10 && !gameHwnd; i++) |
| 62 | + { |
| 63 | + gameHwnd = WindowFinder::FindGameWindow(); |
| 64 | + if (!gameHwnd) std::this_thread::sleep_for(500ms); |
| 65 | + } |
| 66 | + |
| 67 | + if (!gameHwnd) { |
| 68 | + LOG_ERROR(X("Failed to find game window for external overlay!")); |
| 69 | + goto exit; |
| 70 | + } |
| 71 | + |
| 72 | + LOG_INFO(X("Found game window: {}"), reinterpret_cast<uint64_t>(gameHwnd)); |
| 73 | + |
| 74 | + const auto externalOverlay = std::make_unique<ExternalOverlay>(); |
| 75 | + if (!externalOverlay->Create(gameHwnd)) |
| 76 | + { |
| 77 | + LOG_ERROR(X("Failed to create external overlay!")); |
| 78 | + goto exit; |
| 79 | + } |
| 80 | + |
| 81 | + config->externalOverlay = externalOverlay.get(); |
| 82 | + InputForwarder::Initialize(externalOverlay->GetOverlayHwnd(), gameHwnd); |
| 83 | + externalOverlay->SetInputCapture(config->ShowImGui); |
| 84 | + |
| 85 | + LOG_INFO(X("External overlay initialized successfully.")); |
| 86 | + externalOverlay->RunRenderLoop(); |
| 87 | + |
| 88 | + config->externalOverlay = nullptr; |
| 89 | + InputForwarder::Shutdown(); |
| 90 | + externalOverlay->Destroy(); |
| 91 | + LOG_INFO(X("External overlay shut down.")); |
| 92 | + } |
| 93 | + else |
| 94 | + { |
| 95 | + dx_hook::Hk11::SetWndProc(Window::MyWndProc); |
60 | 96 | } |
61 | | - dx_hook::Hk11::SetWndProc(Window::MyWndProc); |
| 97 | + |
62 | 98 | return; |
63 | 99 |
|
64 | 100 | exit: |
|
0 commit comments