From b233778ae0497bdbfe50e851635773cfd30c7f0e Mon Sep 17 00:00:00 2001 From: Anonymous275 <36374260+Anonymous-275@users.noreply.github.com> Date: Sat, 1 Oct 2022 20:56:45 +0300 Subject: [PATCH] - shutdown if two launchers are open with no game - send message if launcher is skipping a channel --- include/Memory/Memory.h | 1 + src/Launcher.cpp | 6 ++++++ src/Memory/Memory.cpp | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/include/Memory/Memory.h b/include/Memory/Memory.h index 386d1ca..5525988 100644 --- a/include/Memory/Memory.h +++ b/include/Memory/Memory.h @@ -11,6 +11,7 @@ class Memory { public: static uint64_t FindPattern(const char* module, const char* Pattern[]); static uint32_t GetBeamNGPID(const std::set& BL); + static uint32_t GetLauncherPID(const std::set& BL); static uint64_t GetModuleBase(const char* Name); static void Print(const std::string& msg); static void Inject(uint32_t PID); diff --git a/src/Launcher.cpp b/src/Launcher.cpp index 2417675..878d6f4 100644 --- a/src/Launcher.cpp +++ b/src/Launcher.cpp @@ -118,10 +118,16 @@ void Launcher::LaunchGame() { void Launcher::WaitForGame() { std::set BlackList; + int chan = 1; do { auto PID = Memory::GetBeamNGPID(BlackList); + if(PID == 0 && BlackList.empty() && Memory::GetLauncherPID({GetCurrentProcessId()})) { + Shutdown.store(true); + break; + } if (PID != 0 && IPC::mem_used(PID)) { BlackList.emplace(PID); + LOG(INFO) << "Skipping Channel #" << chan++; } else { GamePID = PID; } diff --git a/src/Memory/Memory.cpp b/src/Memory/Memory.cpp index df95df2..0166cd0 100644 --- a/src/Memory/Memory.cpp +++ b/src/Memory/Memory.cpp @@ -35,6 +35,28 @@ uint32_t Memory::GetBeamNGPID(const std::set& BL) { return pe32.th32ProcessID; } +uint32_t Memory::GetLauncherPID(const std::set& BL) { + SetLastError(0); + PROCESSENTRY32 pe32; + pe32.dwSize = sizeof(PROCESSENTRY32); + HANDLE Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + + if (Process32First(Snapshot, &pe32)) { + do { + if (std::string("BeamMP-Launcher.exe") == pe32.szExeFile && + BL.find(pe32.th32ProcessID) == BL.end() && + BL.find(pe32.th32ParentProcessID) == BL.end()) { + break; + } + } while (Process32Next(Snapshot, &pe32)); + } + + if (Snapshot != INVALID_HANDLE_VALUE) { CloseHandle(Snapshot); } + + if (GetLastError() != 0) return 0; + return pe32.th32ProcessID; +} + uint64_t Memory::GetModuleBase(const char* Name) { return (uint64_t)GetModuleHandleA(Name); }