| 115 | #endif |
| 116 | |
| 117 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID) |
| 118 | { |
| 119 | switch (fdwReason) |
| 120 | { |
| 121 | case DLL_PROCESS_ATTACH: |
| 122 | { |
| 123 | // Do NOT call 'DisableThreadLibraryCalls', since we are linking against the static CRT, which requires the thread notifications to work properly |
| 124 | // It does not do anything when static TLS is used anyway, which is the case (see https://docs.microsoft.com/windows/win32/api/libloaderapi/nf-libloaderapi-disablethreadlibrarycalls) |
| 125 | g_module_handle = hModule; |
| 126 | g_reshade_dll_path = get_module_path(hModule); |
| 127 | g_target_executable_path = get_module_path(nullptr); |
| 128 | |
| 129 | const std::filesystem::path module_name = g_reshade_dll_path.stem(); |
| 130 | |
| 131 | const bool is_d3d = _wcsnicmp(module_name.c_str(), L"d3d", 3) == 0; |
| 132 | const bool is_dxgi = _wcsicmp(module_name.c_str(), L"dxgi") == 0; |
| 133 | const bool is_opengl = _wcsicmp(module_name.c_str(), L"opengl32") == 0; |
| 134 | const bool is_dinput = _wcsnicmp(module_name.c_str(), L"dinput", 6) == 0; |
| 135 | const bool is_asi = g_reshade_dll_path.extension() == L".asi"; |
| 136 | |
| 137 | // UWP apps do not have write access to the application directory, so never default the base path to it for them |
| 138 | const bool default_base_to_target_executable_path = !is_d3d && !is_dxgi && !is_opengl && !is_dinput && !is_asi && !is_uwp_app(); |
| 139 | |
| 140 | g_reshade_base_path = get_base_path(default_base_to_target_executable_path); |
| 141 | |
| 142 | const reshade::ini_file &config = reshade::global_config(); |
| 143 | |
| 144 | // When ReShade is not loaded by proxy, only actually load when a configuration file exists for the target executable |
| 145 | // This e.g. prevents loading the implicit Vulkan layer when not explicitly enabled for an application |
| 146 | if (default_base_to_target_executable_path && !GetEnvironmentVariableW(L"RESHADE_DISABLE_LOADING_CHECK", nullptr, 0)) |
| 147 | { |
| 148 | #ifndef NDEBUG |
| 149 | // Avoid loading in the ReShade test application |
| 150 | if (g_target_executable_path.filename() == |
| 151 | #ifndef _WIN64 |
| 152 | L"ReShade32.exe" |
| 153 | #else |
| 154 | L"ReShade64.exe" |
| 155 | #endif |
| 156 | ) |
| 157 | { |
| 158 | return FALSE; |
| 159 | } |
| 160 | #endif |
| 161 | |
| 162 | std::error_code ec; |
| 163 | if (!std::filesystem::exists(config.path(), ec)) |
| 164 | { |
| 165 | #ifndef NDEBUG |
| 166 | // Log was not yet opened at this point, so this only writes to debug output |
| 167 | reshade::log::message(reshade::log::level::warning, "ReShade was not enabled for '%s'! Aborting initialization ...", g_target_executable_path.u8string().c_str()); |
| 168 | #endif |
| 169 | return FALSE; // Make the 'LoadLibrary' call that loaded this instance fail |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (config.get("INSTALL", "Logging") || (!config.has("INSTALL", "Logging") && !GetEnvironmentVariableW(L"RESHADE_DISABLE_LOGGING", nullptr, 0))) |
| 174 | { |
nothing calls this directly
no test coverage detected