From ae650cc1420369f3ce2496d6206a23360b816ac5 Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Fri, 28 Mar 2025 23:16:37 +0100 Subject: [PATCH 1/2] Get error code when the game fails to launch on windows --- src/GameStart.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index f94012b..e3a89d8 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -90,6 +90,8 @@ void StartGame(std::string Dir) { gameArgs += options.game_arguments[i]; } + debug("BeamNG executable path: " + Dir); + bSuccess = CreateProcessA(nullptr, (LPSTR)(Dir + gameArgs).c_str(), nullptr, nullptr, TRUE, 0, nullptr, BaseDir.c_str(), &si, &pi); if (bSuccess) { info("Game Launched!"); @@ -97,7 +99,19 @@ void StartGame(std::string Dir) { WaitForSingleObject(pi.hProcess, INFINITE); error("Game Closed! launcher closing soon"); } else { - error("Failed to Launch the game! launcher closing soon"); + std::string err = ""; + + DWORD dw = GetLastError(); + LPVOID lpMsgBuf; + + if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, nullptr) == 0) { + err = "Unknown error code: " + std::to_string(dw); + } else { + err = "Error " + std::to_string(dw) + ": " + (char*)lpMsgBuf; + } + + error("Failed to Launch the game! launcher closing soon. " + err); } std::this_thread::sleep_for(std::chrono::seconds(5)); exit(2); From 6597fe5e26e25c88f70efd18efe2d361e2bb2ecb Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Sat, 19 Apr 2025 21:23:51 +0200 Subject: [PATCH 2/2] Rename windows api variable --- src/GameStart.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index e3a89d8..6216313 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -102,13 +102,13 @@ void StartGame(std::string Dir) { std::string err = ""; DWORD dw = GetLastError(); - LPVOID lpMsgBuf; + LPVOID lpErrorMsgBuffer; if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, nullptr) == 0) { + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpErrorMsgBuffer, 0, nullptr) == 0) { err = "Unknown error code: " + std::to_string(dw); } else { - err = "Error " + std::to_string(dw) + ": " + (char*)lpMsgBuf; + err = "Error " + std::to_string(dw) + ": " + (char*)lpErrorMsgBuffer; } error("Failed to Launch the game! launcher closing soon. " + err);