mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-19 23:20:57 +00:00
added blocking WaitForGame using PID
This commit is contained in:
+3
-2
@@ -41,16 +41,17 @@ add_executable(${PROJECT_NAME}
|
|||||||
src/Network/Http.cpp include/Http.h
|
src/Network/Http.cpp include/Http.h
|
||||||
src/Network/Login.cpp src/Network/Update.cpp
|
src/Network/Login.cpp src/Network/Update.cpp
|
||||||
src/Discord.cpp src/Config.cpp
|
src/Discord.cpp src/Config.cpp
|
||||||
|
src/Memory/Memory.cpp include/Memory.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
ZLIB::ZLIB discord-rpc OpenSSL::SSL OpenSSL::Crypto ws2_32 wx::net wx::core wx::base)
|
ZLIB::ZLIB discord-rpc OpenSSL::SSL OpenSSL::Crypto ws2_32 wx::net wx::core wx::base Dbghelp)
|
||||||
else(WIN32) #MINGW
|
else(WIN32) #MINGW
|
||||||
add_definitions("-D_WIN32_WINNT=0x0600")
|
add_definitions("-D_WIN32_WINNT=0x0600")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
||||||
target_link_libraries(${PROJECT_NAME} discord-rpc ssl crypto ws2_32 ssp crypt32 z)
|
target_link_libraries(${PROJECT_NAME} discord-rpc ssl crypto ws2_32 ssp crypt32 z Dbghelp)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)
|
add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE "include")
|
target_include_directories(${PROJECT_NAME} PRIVATE "include")
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public: //available functions
|
|||||||
std::string Login(const std::string& fields);
|
std::string Login(const std::string& fields);
|
||||||
void RunDiscordRPC();
|
void RunDiscordRPC();
|
||||||
void QueryRegistry();
|
void QueryRegistry();
|
||||||
|
void WaitForGame();
|
||||||
void LoadConfig();
|
void LoadConfig();
|
||||||
void LaunchGame();
|
void LaunchGame();
|
||||||
void CheckKey();
|
void CheckKey();
|
||||||
@@ -41,6 +42,7 @@ private: //functions
|
|||||||
void UpdateCheck();
|
void UpdateCheck();
|
||||||
void Relaunch();
|
void Relaunch();
|
||||||
private: //variables
|
private: //variables
|
||||||
|
size_t GamePID{0};
|
||||||
bool EnableUI = true;
|
bool EnableUI = true;
|
||||||
bool Shutdown = false;
|
bool Shutdown = false;
|
||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
///
|
||||||
|
/// Created by Anonymous275 on 6/17/21
|
||||||
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
|
///
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
class Memory {
|
||||||
|
public:
|
||||||
|
static size_t GetProcessID(const char* PName);
|
||||||
|
static size_t GetModuleBase(const char* Name);
|
||||||
|
};
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Memory.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
|
|
||||||
@@ -41,6 +42,20 @@ void Launcher::LaunchGame() {
|
|||||||
//ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
|
//ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Launcher::WaitForGame() {
|
||||||
|
LOG(INFO) << "Waiting for game launch";
|
||||||
|
int Timeout = 0;
|
||||||
|
do{
|
||||||
|
Timeout++;
|
||||||
|
GamePID = Memory::GetProcessID("BeamNG.drive.x64.exe");
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
|
}while(GamePID == 0 && !Shutdown && Timeout < 600);
|
||||||
|
if(GamePID == 0) {
|
||||||
|
LOG(FATAL) << "Game process not found! aborting";
|
||||||
|
throw ShutdownException("Fatal Error");
|
||||||
|
}else LOG(INFO) << "Game found! PID " << GamePID;
|
||||||
|
}
|
||||||
|
|
||||||
void Launcher::WindowsInit() {
|
void Launcher::WindowsInit() {
|
||||||
system("cls");
|
system("cls");
|
||||||
SetConsoleTitleA(("BeamMP Launcher v" + FullVersion).c_str());
|
SetConsoleTitleA(("BeamMP Launcher v" + FullVersion).c_str());
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
///
|
||||||
|
/// Created by Anonymous275 on 6/17/21
|
||||||
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
|
///
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <string>
|
||||||
|
#include "Memory.h"
|
||||||
|
#undef UNICODE
|
||||||
|
#include <windows.h>
|
||||||
|
#include <tlhelp32.h>
|
||||||
|
|
||||||
|
size_t Memory::GetProcessID(const char* PName) {
|
||||||
|
SetLastError(0);
|
||||||
|
PROCESSENTRY32 pe32;
|
||||||
|
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||||
|
HANDLE Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||||
|
|
||||||
|
if(Process32First(Snapshot, &pe32)) {
|
||||||
|
do{
|
||||||
|
if(std::string(PName) == pe32.szExeFile)break;
|
||||||
|
}while(Process32Next(Snapshot, &pe32));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Snapshot != INVALID_HANDLE_VALUE) {
|
||||||
|
CloseHandle(Snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(GetLastError() != 0)return 0;
|
||||||
|
return pe32.th32ProcessID;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Memory::GetModuleBase(const char* Name) {
|
||||||
|
return (size_t)GetModuleHandleA(Name);
|
||||||
|
}
|
||||||
+4
-3
@@ -13,13 +13,14 @@ int main(int argc, char* argv[]) {
|
|||||||
launcher.LoadConfig();
|
launcher.LoadConfig();
|
||||||
launcher.CheckKey();
|
launcher.CheckKey();
|
||||||
launcher.QueryRegistry();
|
launcher.QueryRegistry();
|
||||||
launcher.LaunchGame();
|
|
||||||
//launcher.WaitForGame();
|
|
||||||
//UI call
|
//UI call
|
||||||
|
//download mod
|
||||||
|
launcher.LaunchGame();
|
||||||
|
launcher.WaitForGame();
|
||||||
|
|
||||||
|
|
||||||
} catch (const ShutdownException& e) {
|
} catch (const ShutdownException& e) {
|
||||||
LOG(INFO) << "Launcher shutting down, reason: " << e.what();
|
LOG(INFO) << "Launcher shutting down with reason: " << e.what();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
LOG(FATAL) << e.what();
|
LOG(FATAL) << e.what();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user