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

Function DllMain

bwapi/BWAPI/Source/DLLMain.cpp:234–280  ·  view source on GitHub ↗

------------------------------------------------- DLL MAIN -------------------------------------------------

Source from the content-addressed store, hash-verified

232
233//------------------------------------------------- DLL MAIN -------------------------------------------------
234BOOL APIENTRY DllMain(HMODULE, DWORD ul_reason_for_call, LPVOID)
235{
236 // Event to prevent the injection of more than one BWAPI DLL
237 static HANDLE hEvent = nullptr;
238 static HANDLE hPersistThread = nullptr;
239
240 switch (ul_reason_for_call)
241 {
242 case DLL_PROCESS_DETACH:
243 if ( hEvent != nullptr )
244 CloseHandle(hEvent); // destroy the event
245
246 if (hPersistThread != nullptr)
247 CloseHandle(hPersistThread); // destroy the thread
248 break;
249 case DLL_PROCESS_ATTACH:
250 {
251 // Create a BWAPI event for this process
252 hEvent = CreateUniqueEvent();
253 if (!hEvent) // There is a BWAPI module already injected
254 return FALSE; // Prevent the injection of this DLL
255
256 // Workaround for injection failures in WINE. The issue is caused by WINE not correctly
257 // loading statically linked libraries upon injection, for some reason this fixes it.
258 // Note that Storm's SFile module is re-initialized upon loading any file.
259 SFileDestroy();
260
261 // Load and attach a console to Broodwar if it was asked for in the config file
262 CheckAttachConsole();
263
264 // Sets debug information
265 SetDebug();
266
267 // Do version checking
268 CheckVersion();
269
270 // Apply all hacks and patches to the game
271 ApplyCodePatches();
272
273 // Create our thread that persistently applies hacks
274 hPersistThread = CreateThread(NULL, 0, &PersistentPatch, NULL, 0, NULL);
275
276 break;
277 }
278 }
279 return TRUE;
280}

Callers

nothing calls this directly

Calls 5

CreateUniqueEventFunction · 0.85
CheckAttachConsoleFunction · 0.85
SetDebugFunction · 0.85
CheckVersionFunction · 0.85
ApplyCodePatchesFunction · 0.85

Tested by

no test coverage detected