Allow non-code mods to exist

This commit is contained in:
PJB3005
2026-05-15 23:46:41 +02:00
parent 9823ca7c4a
commit fb9ffb444a
4 changed files with 17 additions and 6 deletions
+1
View File
@@ -29,6 +29,7 @@ struct ModMetadata {
std::string version;
std::string author;
std::string description;
bool hasCode;
};
struct NativeMod {
+12 -4
View File
@@ -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);
+2 -1
View File
@@ -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
}
+2 -1
View File
@@ -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
}