diff --git a/loader/launcher/windows/proxyLoader.cpp b/loader/launcher/windows/proxyLoader.cpp index 106d8d1c..dad9ee15 100644 --- a/loader/launcher/windows/proxyLoader.cpp +++ b/loader/launcher/windows/proxyLoader.cpp @@ -1,6 +1,5 @@ #include #include -#include struct XINPUT_STATE; struct XINPUT_CAPABILITIES; @@ -54,8 +53,21 @@ static std::wstring getErrorString(DWORD error) { return L"Could not load Geode! Error code: " + std::to_wstring(error); } -static std::wstring get1114ErrorString(DWORD error) { - return L"Could not load Geode! Error code: " + std::to_wstring(error) + L"\n\nDo you want to update Microsoft Visual C++ Redistributable 2022 to try to fix this issue?"; +static DWORD errorThread(LPVOID param) { + constexpr wchar_t REDIST_ERROR[] = L"Could not load Geode!\n" + "This is likely due to an outdated redist package.\n" + "Do you want to update Microsoft Visual C++ Redistributable 2022 to try to fix this issue?"; + const DWORD error = reinterpret_cast(param); + + if (error == ERROR_DLL_INIT_FAILED) { + const auto choice = MessageBoxW(NULL, REDIST_ERROR, L"Load failed", MB_YESNO | MB_ICONWARNING); + if (choice == IDYES) + ShellExecuteW(NULL, L"open", L"https://aka.ms/vs/17/release/vc_redist.x64.exe", NULL, NULL, SW_SHOWNORMAL); + } else { + MessageBoxW(NULL, getErrorString(error).c_str(), L"Load failed" , MB_OK | MB_ICONWARNING); + } + + return 0u; } BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) { @@ -64,18 +76,8 @@ BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) { // This is UB. if (LoadLibraryW(L"Geode.dll") == NULL) { - auto error = GetLastError(); - - if(error == 1114) { - if(MessageBoxW(NULL, get1114ErrorString(error).c_str(), L"Load failed" , MB_YESNO | MB_ICONWARNING) == IDYES) { - std::thread([]() { - ShellExecuteW(NULL, L"open", L"https://aka.ms/vs/17/release/vc_redist.x64.exe", NULL, NULL, SW_SHOWNORMAL); - }).detach(); - } - } else { - MessageBoxW(NULL, getErrorString(error).c_str(), L"Load failed" , MB_OK | MB_ICONWARNING); - } - + const auto param = reinterpret_cast(static_cast(GetLastError())); + CreateThread(NULL, 0, &errorThread, param, 0, NULL); } }