Skip to content

Commit 77e44f5

Browse files
committed
fix(Init): Don't force game to wait for UE4SS if manually injecting
1 parent f66507e commit 77e44f5

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

UE4SS/src/main_ue4ss_rewritten.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,27 @@ auto thread_dll_start(UE4SSProgram* program) -> unsigned long
4040
return 0;
4141
}
4242

43-
auto process_initialized(HMODULE moduleHandle) -> void
43+
struct ProcessInitializedParams
44+
{
45+
HMODULE moduleHandle{};
46+
bool wait_for_ue4ss{};
47+
};
48+
49+
auto process_initialized(ProcessInitializedParams* params) -> void
4450
{
4551
wchar_t moduleFilenameBuffer[1024]{'\0'};
46-
GetModuleFileNameW(moduleHandle, moduleFilenameBuffer, sizeof(moduleFilenameBuffer) / sizeof(wchar_t));
52+
GetModuleFileNameW(params->moduleHandle, moduleFilenameBuffer, sizeof(moduleFilenameBuffer) / sizeof(wchar_t));
4753

4854
auto program = new UE4SSProgram(moduleFilenameBuffer, {});
4955
if (HANDLE handle = CreateThread(nullptr, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(thread_dll_start), (LPVOID)program, 0, nullptr); handle)
5056
{
5157
CloseHandle(handle);
5258
}
5359

54-
UE4SSProgram::cpp_mods_done_loading.wait(false, std::memory_order_relaxed);
60+
if (params->wait_for_ue4ss)
61+
{
62+
UE4SSProgram::cpp_mods_done_loading.wait(false, std::memory_order_relaxed);
63+
}
5564
}
5665

5766
auto get_main_thread_id() -> DWORD
@@ -109,11 +118,13 @@ auto dll_process_attached(HMODULE moduleHandle) -> void
109118
// injected through proxy
110119
if (GetCurrentThreadId() == get_main_thread_id())
111120
{
112-
QueueUserAPC((PAPCFUNC)process_initialized, GetCurrentThread(), (ULONG_PTR)moduleHandle);
121+
ProcessInitializedParams params{moduleHandle, true};
122+
QueueUserAPC((PAPCFUNC)process_initialized, GetCurrentThread(), (ULONG_PTR)&params);
113123
}
114124
else // injected manually -> thread id different from main
115125
{
116-
process_initialized(moduleHandle);
126+
ProcessInitializedParams params{moduleHandle, false};
127+
process_initialized(&params);
117128
}
118129
}
119130

0 commit comments

Comments
 (0)