bool WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved) { TCHAR fileName[512]; GetModuleFileName(NULL, fileName, 512); if(dwReason == DLL_PROCESS_ATTACH) { DisableThreadLibraryCalls(hDll); GetModuleFileName(hDll, dlldir, 512); for(int i = strlen(dlldir); i > 0; i--) { if(dlldir[i] == '\\') { dlldir[i+1] = 0; break; } } ofile.open(GetDirectoryFile("DSfix.log"), std::ios::out); sdlogtime(); SDLOG(0, "===== start DSfix %s = fn: %s\n", VERSION, fileName); // load settings Settings::get().load(); Settings::get().report(); KeyActions::get().load(); KeyActions::get().report(); // load original dinput8.dll HMODULE hMod; if(Settings::get().getDinput8dllWrapper().empty() || (Settings::get().getDinput8dllWrapper().find("none") == 0)) { char syspath[320]; GetSystemDirectory(syspath, 320); strcat_s(syspath, "\\dinput8.dll"); hMod = LoadLibrary(syspath); } else { sdlog(0, "Loading dinput wrapper %s\n", Settings::get().getDinput8dllWrapper().c_str()); hMod = LoadLibrary(Settings::get().getDinput8dllWrapper().c_str()); } if(!hMod) { sdlog("Could not load original dinput8.dll\nABORTING.\n"); errorExit("Loading of specified dinput wrapper"); } oDirectInput8Create = (tDirectInput8Create)GetProcAddress(hMod, "DirectInput8Create"); SaveManager::get().init(); earlyDetour(); if(Settings::get().getUnlockFPS()) applyFPSPatch(); return true; } else if(dwReason == DLL_PROCESS_DETACH) { Settings::get().shutdown(); endDetour(); SDLOG(0, "===== end = fn: %s\n", fileName); if(ofile) { ofile.close(); } } return false; }
BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved) { if(dwReason == DLL_PROCESS_ATTACH) { OutputDebugString("GeDoSaTo: startup"); // read install location from registry getInstallDirectory(); OutputDebugString("GeDoSaTo: Got install dir"); // don't attach to processes on the blacklist / not on the whitelist if(getUseBlacklist() ? onList(getExeFileName(), "blacklist.txt") : !onList(getExeFileName(), "whitelist.txt")) { OutputDebugString("GeDoSaTo: blacklisted / not whitelisted"); if(getExeFileName() == "GeDoSaToTool") return true; return true; } g_active = true; OutputDebugString("GeDoSaTo: Active"); // initialize log string logFn = format("logs\\%s_%s.log", getExeFileName().c_str(), getTimeString().c_str()); std::replace(logFn.begin(), logFn.end(), ':', '-'); std::replace(logFn.begin(), logFn.end(), ' ', '_'); logFn = getInstalledFileName(logFn); fopen_s(&g_oFile, logFn.c_str(), "w"); if(!g_oFile) OutputDebugString(format("GeDoSaTo: Error opening log fn %s", logFn.c_str()).c_str()); else OutputDebugString(format("GeDoSaTo: Opening log fn %s, handle: %p", logFn.c_str(), g_oFile).c_str()); OutputDebugString("GeDoSaTo: Log file initialized, let that take over"); // startup sdlogtime(-1); SDLOG(-1, "===== start "INTERCEPTOR_NAME" %s = fn: %s\n", GeDoSaToVersion(), getExeFileName().c_str()); SDLOG(-1, "===== installation directory: %s\n", getInstallDirectory().c_str()); // load settings Settings::get().load(); Settings::get().report(); KeyActions::get().load(); KeyActions::get().report(); if(!Settings::get().getPreventSteamOverlay() && Settings::get().getLoadSteamOverlayEarly()) { SDLOG(2, "Attempting to pre-load Steam overlay dll.\n"); LoadLibrary("gameoverlayrenderer.dll"); } if(Settings::get().getLoadD3DEarly()) { SDLOG(2, "Early d3d loading.\n"); auto dllname = getSystemDllName("d3d9.dll"); LoadLibrary(dllname.c_str()); } // detour startDetour(); return true; } if(dwReason == DLL_PROCESS_DETACH && g_active) { Settings::get().shutdown(); endDetour(); SDLOG(-1, "===== end =\n"); fclose(g_oFile); } return false; }