From f1d960d062d309782d0add127afd2f6e7b5fc7cf Mon Sep 17 00:00:00 2001 From: Anonymous-275 <36374260+Anonymous-275@users.noreply.github.com> Date: Fri, 4 Aug 2023 20:57:52 +0100 Subject: [PATCH] - debug state - new fail message from pull/58 --- include/Launcher.h | 1 + include/Memory/Memory.h | 3 ++- src/Launcher.cpp | 11 +++++++++-- src/Memory/Memory.cpp | 10 ++++++---- src/Network/Update.cpp | 32 ++++++++++++++++++++------------ 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/include/Launcher.h b/include/Launcher.h index c9add42..7b43969 100644 --- a/include/Launcher.h +++ b/include/Launcher.h @@ -79,6 +79,7 @@ class Launcher { fs::path LauncherCache{"Resources"}; int64_t DiscordTime{}; bool LoginAuth = false; + bool DebugMode = false; fs::path CurrentPath{}; std::string BeamRoot{}; std::string UserRole{}; diff --git a/include/Memory/Memory.h b/include/Memory/Memory.h index acb4167..6aa29fe 100644 --- a/include/Memory/Memory.h +++ b/include/Memory/Memory.h @@ -14,7 +14,8 @@ class Memory { static uint32_t GetLauncherPID(const std::set& BL); static uint64_t GetModuleBase(const char* Name); static void Print(const std::string& msg); - static std::string GetHex(uint64_t num); + static std::string GetHex(uint64_t num); + static inline bool DebugMode = false; static void Inject(uint32_t PID); static uint32_t GetTickCount(); static uint32_t EntryPoint(); diff --git a/src/Launcher.cpp b/src/Launcher.cpp index 913e321..33497a5 100644 --- a/src/Launcher.cpp +++ b/src/Launcher.cpp @@ -32,8 +32,15 @@ Launcher::Launcher(int argc, char* argv[]) : WindowsInit(); SetUnhandledExceptionFilter(CrashHandler); LOG(INFO) << "Starting Launcher v" << FullVersion; - if (argc > 1) LoadConfig(fs::current_path() / argv[1]); - else LoadConfig(fs::current_path() / "Launcher.toml"); + if (argc > 1) { + if(std::string(argv[1]).find('0') != std::string::npos) { + DebugMode = true; + Memory::DebugMode = true; + LoadConfig(fs::current_path() / "Launcher.toml"); + } else { + LoadConfig(fs::current_path() / argv[1]); + } + } else LoadConfig(fs::current_path() / "Launcher.toml"); } void Launcher::Abort() { diff --git a/src/Memory/Memory.cpp b/src/Memory/Memory.cpp index ce7d2a6..8e91ba3 100644 --- a/src/Memory/Memory.cpp +++ b/src/Memory/Memory.cpp @@ -171,10 +171,12 @@ void Memory::Print(const std::string& msg) { } uint32_t Memory::EntryPoint() { - AllocConsole(); - SetConsoleTitleA("BeamMP Console"); - BeamNG::EntryPoint(); - return 0; + if (Memory::DebugMode) { + AllocConsole(); + SetConsoleTitleA("BeamMP Console"); + } + BeamNG::EntryPoint(); + return 0; } uint32_t Memory::GetTickCount() { diff --git a/src/Network/Update.cpp b/src/Network/Update.cpp index ee61734..c2334df 100644 --- a/src/Network/Update.cpp +++ b/src/Network/Update.cpp @@ -41,19 +41,23 @@ size_t DirCount(const std::filesystem::path& path) { } void Launcher::ResetMods() { - if (!fs::exists(MPUserPath)) { - fs::create_directories(MPUserPath); - return; - } - if (DirCount(MPUserPath) > 3) { - LOG(WARNING) - << "mods/multiplayer will be cleared in 15 seconds, close to abort"; - std::this_thread::sleep_for(std::chrono::seconds(15)); - } - for (auto &de: std::filesystem::directory_iterator(MPUserPath)) { - if (de.path().filename() != "BeamMP.zip") { - std::filesystem::remove(de.path()); + try { + if (!fs::exists(MPUserPath)) { + fs::create_directories(MPUserPath); + return; } + if (DirCount(MPUserPath) > 3) { + LOG(WARNING) + << "mods/multiplayer will be cleared in 15 seconds, close to abort"; + std::this_thread::sleep_for(std::chrono::seconds(15)); + } + for (auto &de: std::filesystem::directory_iterator(MPUserPath)) { + if (de.path().filename() != "BeamMP.zip") { + std::filesystem::remove(de.path()); + } + } + } catch (...) { + throw ShutdownException("We were unable to clean the multiplayer mods folder! Is the game still running or do you have something open in that folder?"); } } @@ -103,6 +107,10 @@ void Launcher::SetupMOD() { } void Launcher::UpdateCheck() { + if(DebugMode){ + LOG(DEBUG) << "Debug mode active skipping update checks"; + return; + } std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/launcher?branch=" + TargetBuild + "&pk=" + PublicKey); transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);