-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdllmain.cpp
More file actions
75 lines (61 loc) · 1.64 KB
/
Copy pathdllmain.cpp
File metadata and controls
75 lines (61 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <Windows.h>
#include "hooks/hooks.h"
#include "SDK/fb.h"
#include <thread>
std::jthread g_initThread;
static void initThread(std::stop_token stopToken)
{
#if defined(BFVE_GAME_BF3)
while (!stopToken.stop_requested())
{
if (fb::DxRenderer::GetInstance() && fb::DxRenderer::GetInstance()->pSwapChain)
break;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
#elif defined(BFVE_GAME_BF4)
while (!stopToken.stop_requested())
{
auto* dx = fb::DxRenderer::GetInstance();
const bool swapReady = dx && dx->m_pScreen && dx->m_pScreen->m_pSwapChain;
const bool veReady = fb::VisualEnvironmentManager::GetInstance() != nullptr;
if (swapReady && veReady)
break;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
#endif
if (stopToken.stop_requested())
return;
#if defined(_DEBUG)
AllocConsole();
FILE* dummy;
freopen_s(&dummy, "CONOUT$", "w", stdout);
freopen_s(&dummy, "CONOUT$", "w", stderr);
SetConsoleTitleA("VisEnv Debug");
#endif
if (!hooks::init())
{
return;
}
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
DisableThreadLibraryCalls(hModule);
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
g_initThread = std::jthread{ initThread };
}
else if (ul_reason_for_call == DLL_PROCESS_DETACH)
{
g_initThread.request_stop();
if (g_initThread.joinable())
g_initThread.join();
hooks::shutdown();
#ifdef _DEBUG
FreeConsole();
#endif
}
return TRUE;
}