Skip to content

Commit e648df5

Browse files
committed
Add external overlay as fallback
1 parent c55f3e1 commit e648df5

12 files changed

Lines changed: 655 additions & 47 deletions

File tree

UnityInspector/UnityInspector.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@
178178
<ClInclude Include="src\pch\pch.h" />
179179
<ClInclude Include="src\game\sdk\sdk.h" />
180180
<ClInclude Include="src\gui\window\window.h" />
181+
<ClInclude Include="src\gui\window\window_finder.h" />
182+
<ClInclude Include="src\gui\window\external_overlay.h" />
183+
<ClInclude Include="src\gui\window\input_forwarder.h" />
181184
</ItemGroup>
182185
<ItemGroup>
183186
<ClCompile Include="src\dllmain.cpp" />
@@ -228,6 +231,9 @@
228231
<ClCompile Include="src\game\hooks\hooks.cpp" />
229232
<ClCompile Include="src\gui\menu\menu.cpp" />
230233
<ClCompile Include="src\gui\window\window.cpp" />
234+
<ClCompile Include="src\gui\window\window_finder.cpp" />
235+
<ClCompile Include="src\gui\window\external_overlay.cpp" />
236+
<ClCompile Include="src\gui\window\input_forwarder.cpp" />
231237
<ClCompile Include="src\pch\pch.cpp">
232238
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
233239
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>

UnityInspector/src/dllmain.cpp

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#include "game/core/core.h"
44
#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"
58

69
static void Init(HMODULE hMod)
710
{
@@ -42,23 +45,56 @@ static void Init(HMODULE hMod)
4245

4346
LOG_INFO(X("initializing Overlay Hook."));
4447

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+
{
4852
LOG_INFO(X("Successfully initialized {} DirectX Hook."), name);
4953
hookSuccess = true;
5054
break;
5155
}
52-
53-
LOG_ERROR(X("Failed to initialize {} DirectX Hook."), name);
5456
}
5557

56-
if (!hookSuccess)
58+
if (!hookSuccess)
5759
{
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);
6096
}
61-
dx_hook::Hk11::SetWndProc(Window::MyWndProc);
97+
6298
return;
6399

64100
exit:

UnityInspector/src/game/config/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22
#include "pch.h"
33

4+
struct ExternalOverlay;
5+
46
struct Config {
57
private:
68
struct Inspector {
@@ -14,5 +16,6 @@ struct Config {
1416
bool ShowImGui = true;
1517
HMODULE gameAssembly = nullptr;
1618
UR::Mode gameMode;
19+
ExternalOverlay* externalOverlay = nullptr;
1720
Inspector inspector;
1821
};

0 commit comments

Comments
 (0)