From acdb8c5578374652ce8a505051e1c2e6fbe06673 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 29 Apr 2025 16:25:19 +0100 Subject: [PATCH] Implement recommendedRam in CurseForge import Signed-off-by: TheKodeToad --- .../flame/FlameInstanceCreationTask.cpp | 19 +++++++++++++++++++ launcher/modplatform/flame/PackManifest.cpp | 1 + launcher/modplatform/flame/PackManifest.h | 1 + 3 files changed, 21 insertions(+) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index c30ba5249..5d9c74ccf 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -54,6 +54,7 @@ #include "settings/INISettingsObject.h" +#include "sys.h" #include "tasks/ConcurrentTask.h" #include "ui/dialogs/BlockedModsDialog.h" #include "ui/dialogs/CustomMessageBox.h" @@ -418,6 +419,24 @@ bool FlameCreationTask::createInstance() } } + int recommendedRAM = m_pack.minecraft.recommendedRAM; + + // only set memory if this is a fresh instance + if (m_instance == nullptr && recommendedRAM > 0) { + const uint64_t sysMiB = Sys::getSystemRam() / Sys::mebibyte; + const uint64_t max = sysMiB * 0.9; + + if (recommendedRAM > max) { + logWarning(tr("The recommended memory of the modpack exceeds 90% of your system RAM—reducing it from %1 MiB to %2 MiB!") + .arg(recommendedRAM) + .arg(max)); + recommendedRAM = max; + } + + instance.settings()->set("OverrideMemory", true); + instance.settings()->set("MaxMemAlloc", recommendedRAM); + } + QString jarmodsPath = FS::PathCombine(m_stagingPath, "minecraft", "jarmods"); QFileInfo jarmodsInfo(jarmodsPath); if (jarmodsInfo.isDir()) { diff --git a/launcher/modplatform/flame/PackManifest.cpp b/launcher/modplatform/flame/PackManifest.cpp index 278105f4a..641fb5d9a 100644 --- a/launcher/modplatform/flame/PackManifest.cpp +++ b/launcher/modplatform/flame/PackManifest.cpp @@ -27,6 +27,7 @@ static void loadMinecraftV1(Flame::Minecraft& m, QJsonObject& minecraft) loadModloaderV1(loader, obj); m.modLoaders.append(loader); } + m.recommendedRAM = Json::ensureInteger(minecraft, "recommendedRam", 0); } static void loadManifestV1(Flame::Manifest& pack, QJsonObject& manifest) diff --git a/launcher/modplatform/flame/PackManifest.h b/launcher/modplatform/flame/PackManifest.h index ebb3ed5cc..6b911ffb4 100644 --- a/launcher/modplatform/flame/PackManifest.h +++ b/launcher/modplatform/flame/PackManifest.h @@ -67,6 +67,7 @@ struct Minecraft { QString version; QString libraries; QList modLoaders; + int recommendedRAM; }; struct Manifest {