Skip to content

Commit

Permalink
Fix postload crash from missing rpak.json (R2Northstar#762)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EM4Volts authored Aug 9, 2024
1 parent a176b70 commit a28c1cb
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions primedev/mods/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a28c1cb

Please sign in to comment.