diff --git a/include/dusk/mod_loader.hpp b/include/dusk/mod_loader.hpp index d48875b4ff..3b467b6db0 100644 --- a/include/dusk/mod_loader.hpp +++ b/include/dusk/mod_loader.hpp @@ -29,6 +29,7 @@ struct ModMetadata { std::string version; std::string author; std::string description; + bool hasCode; }; struct NativeMod { diff --git a/src/dusk/modding/mod_loader.cpp b/src/dusk/modding/mod_loader.cpp index 598b44e79d..b5ba972eaa 100644 --- a/src/dusk/modding/mod_loader.cpp +++ b/src/dusk/modding/mod_loader.cpp @@ -380,6 +380,7 @@ static ModMetadata loadMetadata(const std::filesystem::path& modPath, ModBundle& std::string metaVersion = j.value("version", ""); std::string metaAuthor = j.value("author", ""); std::string metaDescription = j.value("description", ""); + const bool hasCode = j.value("has_code", false); if (metaId.empty()) { throw InvalidModDataException("Missing ID value in mod metadata!"); @@ -400,6 +401,7 @@ static ModMetadata loadMetadata(const std::filesystem::path& modPath, ModBundle& std::move(metaVersion), std::move(metaAuthor), std::move(metaDescription), + hasCode, }; } @@ -515,7 +517,7 @@ void ModLoader::tryLoadDusk(const std::filesystem::path& modPath, bool fromDir) mod.metadata = std::move(metadata); mod.bundle = std::move(bundle); - if (!tryLoadNativeMod(mod)) { + if (mod.metadata.hasCode && !tryLoadNativeMod(mod)) { return; } @@ -571,10 +573,16 @@ void ModLoader::init() { DuskLog.info("ModLoader: initializing {} mod(s)...", m_mods.size()); for (auto& mod : m_mods) { - buildAPI(mod); + if (mod.native) { + buildAPI(mod); + } } for (auto& mod : m_mods) { + if (!mod.native) { + continue; + } + ModGuard guard(&mod); try { mod.native->fn_init(&mod.native->api); @@ -598,7 +606,7 @@ void ModLoader::init() { void ModLoader::tick() { for (auto& mod : m_mods) { - if (!mod.active) { + if (!mod.active || !mod.native) { continue; } ModGuard guard(&mod); @@ -618,7 +626,7 @@ void ModLoader::tick() { void ModLoader::shutdown() { for (auto& mod : m_mods) { hookClearMod(&mod); - if (mod.native->fn_cleanup) { + if (mod.native && mod.native->fn_cleanup) { ModGuard guard(&mod); try { mod.native->fn_cleanup(&mod.native->api); diff --git a/tools/mod_template/mod.json b/tools/mod_template/mod.json index 44364017ee..f920df6dd2 100644 --- a/tools/mod_template/mod.json +++ b/tools/mod_template/mod.json @@ -3,5 +3,6 @@ "name": "Template Mod", "version": "1.0.0", "author": "Maddie", - "description": "An example Dusk mod" + "description": "An example Dusk mod", + "has_code": true } diff --git a/tools/mod_test/mod.json b/tools/mod_test/mod.json index 0e36ab47a2..f36d8abe2d 100644 --- a/tools/mod_test/mod.json +++ b/tools/mod_test/mod.json @@ -3,5 +3,6 @@ "name": "API Test Mod", "version": "1.0.0", "author": "dusk", - "description": "Exercises every feature of the Dusk mod API." + "description": "Exercises every feature of the Dusk mod API.", + "has_code": true }