MCPcopy Create free account
hub / github.com/aliasIsolation/aliasIsolation / DllMain

Function DllMain

src/dll/dllMain.cpp:49–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47void *SetUnhandledExceptionFilter_orig = nullptr;
48
49BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/
50)
51{
52 switch (ul_reason_for_call)
53 {
54 case DLL_PROCESS_ATTACH: {
55 ZoneScoped;
56
57#ifdef _DEBUG
58 AllocConsole();
59 freopen("CONOUT$", "w", stdout);
60 freopen("CONOUT$", "w", stderr);
61#endif
62
63 MH_CHECK(MH_Initialize());
64 LOG_MSG("[aliasIsolation::dllMain] MH_Initialize()\n", "");
65
66 // Set our crash handler and prevent the game from overriding it.
67 installCrashHandler();
68 MH_CHECK(MH_CreateHook(&SetUnhandledExceptionFilter, &SetUnhandledExceptionFilter_hook,
69 &SetUnhandledExceptionFilter_orig));
70 LOG_MSG("[aliasIsolation::dllMain] "
71 "MH_CreateHook(&SetUnhandledExceptionFilter)\n",
72 "");
73 MH_CHECK(MH_EnableHook(&SetUnhandledExceptionFilter));
74 LOG_MSG("[aliasIsolation::dllMain] "
75 "MH_EnableHook(&SetUnhandledExceptionFilter)\n",
76 "");
77
78 std::string settingsFile = getSettingsFilePath();
79 LOG_MSG("[aliasIsolation::dllMain] getSettingsFilePath()\n", "");
80
81 setSettingsFilePath(settingsFile.c_str());
82 LOG_MSG("[aliasIsolation::dllMain] setSettingsFilePath(settingsFile.c_str())\n", "");
83
84 hookRendering();
85 LOG_MSG("[aliasIsolation::dllMain] hookRendering()\n", "");
86
87 HANDLE thread = CreateThread(NULL, NULL, &terminationWatchThread, NULL, NULL, NULL);
88 if (thread != nullptr)
89 {
90 SetThreadDescription(thread, L"AliasIsolation_TerminationWatchThread");
91 }
92 LOG_MSG("[aliasIsolation::dllMain] CreateThread(&terminationWatchThread)\n", "");
93
94 break;
95 }
96 case DLL_PROCESS_DETACH:
97 ZoneScoped;
98
99 unhookRendering();
100 LOG_MSG("[aliasIsolation::dllMain] unhookRendering()\n", "");
101 MH_Uninitialize();
102 LOG_MSG("[aliasIsolation::dllMain] MH_Uninitialize()\n", "");
103
104 break;
105 }
106

Callers

nothing calls this directly

Calls 5

installCrashHandlerFunction · 0.85
getSettingsFilePathFunction · 0.85
setSettingsFilePathFunction · 0.85
hookRenderingFunction · 0.85
unhookRenderingFunction · 0.85

Tested by

no test coverage detected