Add "-- deluxe:" field to mods

This commit is contained in:
Agent X 2023-11-11 14:16:27 -05:00
parent f5e6e816b2
commit ae22eaac98
7 changed files with 26 additions and 1 deletions

View File

@ -1042,6 +1042,7 @@
--- @class Mod
--- @field public basePath string
--- @field public customBehaviorIndex integer
--- @field public deluxe boolean
--- @field public description string
--- @field public enabled boolean
--- @field public fileCount integer

View File

@ -1420,6 +1420,7 @@
| ----- | ---- | ------ |
| basePath | `string` | read-only |
| customBehaviorIndex | `integer` | read-only |
| deluxe | `boolean` | read-only |
| description | `string` | read-only |
| enabled | `boolean` | read-only |
| fileCount | `integer` | read-only |

View File

@ -1160,10 +1160,11 @@ static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = {
{ "waterLevel", LVT_S16, offsetof(struct MarioState, waterLevel), false, LOT_NONE },
};
#define LUA_MOD_FIELD_COUNT 12
#define LUA_MOD_FIELD_COUNT 13
static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = {
{ "basePath", LVT_STRING, offsetof(struct Mod, basePath), true, LOT_NONE },
{ "customBehaviorIndex", LVT_U8, offsetof(struct Mod, customBehaviorIndex), true, LOT_NONE },
{ "deluxe", LVT_BOOL, offsetof(struct Mod, deluxe), true, LOT_NONE },
{ "description", LVT_STRING_P, offsetof(struct Mod, description), true, LOT_NONE },
{ "enabled", LVT_BOOL, offsetof(struct Mod, enabled), true, LOT_NONE },
{ "fileCount", LVT_U16, offsetof(struct Mod, fileCount), true, LOT_NONE },

View File

@ -432,6 +432,8 @@ static void mod_extract_fields(struct Mod* mod) {
if (snprintf(mod->description, MOD_DESCRIPTION_MAX_LENGTH, "%s", extracted) < 0) {
LOG_INFO("Truncated mod description field '%s'", mod->description);
}
} else if (!mod->deluxe && (extracted = extract_lua_field("-- deluxe:", buffer))) {
mod->deluxe = !strcmp(extracted, "true");
}
}

View File

@ -34,6 +34,7 @@ struct Mod {
bool enabled;
bool selectable;
bool renderBehindHud;
bool deluxe;
size_t size;
u8 customBehaviorIndex;
};

View File

@ -3,6 +3,7 @@
#include "mods.h"
#include "mods_utils.h"
#include "pc/debuglog.h"
#include "pc/pc_main.h"
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
@ -25,6 +26,16 @@ void mods_size_enforce(struct Mods* mods) {
}
}
void mods_deluxe_enforce(struct Mods* mods) {
for (int i = 0; i < mods->entryCount; i++) {
struct Mod* mod = mods->entries[i];
if (mod->deluxe && gCoopCompatibility) {
mod->enabled = false;
mod->selectable = false;
}
}
}
static bool mods_incompatible_match(struct Mod* a, struct Mod* b) {
if (a->incompatible == NULL || b->incompatible == NULL) {
return false;
@ -76,6 +87,7 @@ void mods_update_selectable(void) {
}
mods_size_enforce(&gLocalMods);
mods_deluxe_enforce(&gLocalMods);
}
void mods_delete_folder(char* path) {

View File

@ -5,6 +5,7 @@
#include "pc/djui/djui.h"
#include "pc/djui/djui_panel_join_message.h"
#include "pc/debuglog.h"
#include "pc/pc_main.h"
#include "pc/mods/mod_cache.h"
void network_send_mod_list_request(void) {
@ -84,6 +85,9 @@ void network_send_mod_list(void) {
packet_write(&p, mod->relativePath, sizeof(u8) * relativePathLength);
packet_write(&p, &modSize, sizeof(u64));
packet_write(&p, &mod->isDirectory, sizeof(u8));
if (!gCoopCompatibility) {
packet_write(&p, &mod->deluxe, sizeof(u8));
}
packet_write(&p, &mod->fileCount, sizeof(u16));
network_send_to(0, &p);
LOG_INFO(" '%s': %llu", mod->name, (u64)mod->size);
@ -222,6 +226,9 @@ void network_receive_mod_list_entry(struct Packet* p) {
packet_read(p, mod->relativePath, relativePathLength * sizeof(u8));
packet_read(p, &mod->size, sizeof(u64));
packet_read(p, &mod->isDirectory, sizeof(u8));
if (!gCoopCompatibility) {
packet_read(p, &mod->deluxe, sizeof(u8));
}
normalize_path(mod->relativePath);
LOG_INFO(" '%s': %llu", mod->name, (u64)mod->size);