From a28c1cb10cc805907d22b656ccc300b39b720a88 Mon Sep 17 00:00:00 2001 From: FourthVolt <87427011+EM4Volts@users.noreply.github.com> Date: Fri, 9 Aug 2024 20:28:26 +0200 Subject: Fix postload crash from missing `rpak.json` (#762) Missing `rpak.json` would previously crash the game due to faulty boolean logic in the `if` statement. This change ensures that a missing `rpak.json` is handled gracefully. --- primedev/mods/modmanager.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/primedev/mods/modmanager.cpp b/primedev/mods/modmanager.cpp index 68f9bd0f..45eddd3e 100644 --- a/primedev/mods/modmanager.cpp +++ b/primedev/mods/modmanager.cpp @@ -866,16 +866,24 @@ void ModManager::LoadMods() if (fs::is_regular_file(file) && file.path().extension() == ".rpak") { std::string pakName(file.path().filename().string()); - ModRpakEntry& modPak = mod.Rpaks.emplace_back(); - modPak.m_bAutoLoad = - !bUseRpakJson || (dRpakJson.HasMember("Preload") && dRpakJson["Preload"].IsObject() && - dRpakJson["Preload"].HasMember(pakName) && dRpakJson["Preload"][pakName].IsTrue()); - - // postload things - if (!bUseRpakJson || - (dRpakJson.HasMember("Postload") && dRpakJson["Postload"].IsObject() && dRpakJson["Postload"].HasMember(pakName))) - modPak.m_sLoadAfterPak = dRpakJson["Postload"][pakName].GetString(); + + if (!bUseRpakJson) + { + spdlog::warn("Mod {} contains rpaks without valid rpak.json, rpaks might not be loaded", mod.Name); + } + else + { + modPak.m_bAutoLoad = + (dRpakJson.HasMember("Preload") && dRpakJson["Preload"].IsObject() && dRpakJson["Preload"].HasMember(pakName) && + dRpakJson["Preload"][pakName].IsTrue()); + + // postload things + if (dRpakJson.HasMember("Postload") && dRpakJson["Postload"].IsObject() && dRpakJson["Postload"].HasMember(pakName)) + { + modPak.m_sLoadAfterPak = dRpakJson["Postload"][pakName].GetString(); + } + } modPak.m_sPakName = pakName; -- cgit v1.2.3