diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c index 976021bc3..f98091cc3 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -90,7 +90,7 @@ void smlua_init(void) { // load scripts LOG_INFO("Loading scripts:"); - struct ModTable* table = (gNetworkType == NT_SERVER) ? &gModTableLocal : &gModTableRemote; + struct ModTable* table = gModTableCurrent; for (int i = 0; i < table->entryCount; i++) { struct ModListEntry* entry = &table->entries[i]; if (!entry->enabled) { continue; } diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 411a5a70a..83dfc025e 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -155,9 +155,9 @@ int smlua_hook_mario_action(lua_State* L) { return 0; } - lua_Integer action = smlua_to_integer(L, -2); - if (action == 0 || gSmLuaConvertSuccess) { - LOG_LUA("Hook Action: tried to hook invalid action"); + lua_Integer action = smlua_to_integer(L, 1); + if (action == 0 || !gSmLuaConvertSuccess) { + LOG_LUA("Hook Action: tried to hook invalid action: %lld, %u", action, gSmLuaConvertSuccess); smlua_logline(); return 0; } diff --git a/src/pc/lua/smlua_utils.c b/src/pc/lua/smlua_utils.c index 35be95cb1..c3c16be07 100644 --- a/src/pc/lua/smlua_utils.c +++ b/src/pc/lua/smlua_utils.c @@ -51,6 +51,7 @@ bool smlua_to_boolean(lua_State* L, int index) { lua_Integer smlua_to_integer(lua_State* L, int index) { if (lua_type(L, index) == LUA_TBOOLEAN) { + gSmLuaConvertSuccess = true; return lua_toboolean(L, index) ? 1 : 0; } else if (lua_type(L, index) != LUA_TNUMBER) { LOG_LUA("smlua_to_integer received improper type '%d'", lua_type(L, index)); diff --git a/src/pc/mod_list.c b/src/pc/mod_list.c index 549536074..3e33cad97 100644 --- a/src/pc/mod_list.c +++ b/src/pc/mod_list.c @@ -10,6 +10,7 @@ struct ModTable gModTableLocal = { .entries = NULL, .entryCount = 0, .totalSize = 0, .isRemote = false }; struct ModTable gModTableRemote = { .entries = NULL, .entryCount = 0, .totalSize = 0, .isRemote = true }; +struct ModTable* gModTableCurrent = &gModTableLocal; static char sTmpSession[MAX_SESSION_CHARS] = { 0 }; static char sTmpPath[PATH_MAX] = { 0 }; @@ -99,7 +100,7 @@ static char* extract_lua_field(char* fieldName, char* buffer) { return NULL; } -static void extract_lua_fields(struct ModListEntry* entry) { +void mod_list_extract_lua_fields(struct ModListEntry* entry) { FILE* f = entry->fp; char buffer[512] = { 0 }; @@ -107,6 +108,8 @@ static void extract_lua_fields(struct ModListEntry* entry) { entry->incompatible = NULL; entry->description = NULL; + fseek(entry->fp, 0, SEEK_SET); + while (!feof(f)) { file_get_line(buffer, 512, f); @@ -128,6 +131,7 @@ static void extract_lua_fields(struct ModListEntry* entry) { snprintf(entry->description, 512, "%s", extracted); } } + } static void mod_list_add_local(u16 index, const char* path, char* name) { @@ -142,7 +146,7 @@ static void mod_list_add_local(u16 index, const char* path, char* name) { snprintf(entry->path, PATH_MAX - 1, "%s/%s", path, name); entry->fp = fopen(entry->path, "rb"); - extract_lua_fields(entry); + mod_list_extract_lua_fields(entry); fseek(entry->fp, 0, SEEK_END); entry->size = ftell(entry->fp); @@ -292,6 +296,7 @@ static void mod_list_load_local(const char* path) { } void mod_list_init(void) { + gModTableCurrent = &gModTableLocal; srand(time(0)); snprintf(sTmpSession, MAX_SESSION_CHARS, "%06X", (u32)(rand() % 0xFFFFFF)); snprintf(sTmpPath, PATH_MAX - 1, "%s", fs_get_write_path("tmp")); diff --git a/src/pc/mod_list.h b/src/pc/mod_list.h index b39282356..b3bfd0d0d 100644 --- a/src/pc/mod_list.h +++ b/src/pc/mod_list.h @@ -36,8 +36,10 @@ struct ModTable { extern struct ModTable gModTableLocal; extern struct ModTable gModTableRemote; +extern struct ModTable* gModTableCurrent; void mod_list_add_tmp(u16 index, u16 remoteIndex, char* name, size_t size); +void mod_list_extract_lua_fields(struct ModListEntry* entry); void mod_table_clear(struct ModTable* table); void mod_list_alloc(struct ModTable* table, u16 count); diff --git a/src/pc/network/discord/activity.c b/src/pc/network/discord/activity.c index 5ebf35088..c06c13c71 100644 --- a/src/pc/network/discord/activity.c +++ b/src/pc/network/discord/activity.c @@ -4,6 +4,7 @@ #include "pc/network/network.h" #include "pc/network/version.h" #include "pc/djui/djui.h" +#include "pc/mod_list.h" #include "pc/logfile.h" #define HASH_LENGTH 8 @@ -79,17 +80,40 @@ void discord_activity_update(bool hosting) { if (gCurActivity.details[0] == '\0') { snprintf(gCurActivity.details, 128, "%s", get_version()); + + bool displayDash = true; + bool displayComma = false; + if (gRegisteredMods.string != NULL) { strncat(gCurActivity.details, " - ", 127); + displayDash = false; + + // add patches to activity struct StringLinkedList* node = &gRegisteredMods; while (node != NULL && node->string != NULL) { + if (displayComma) { strncat(gCurActivity.details, ", ", 127); } strncat(gCurActivity.details, node->string, 127); + displayComma = true; node = node->next; - if (node != NULL && node->string != NULL) { - strncat(gCurActivity.details, ", ", 127); - } } } + + struct ModTable* table = gModTableCurrent; + if (table != NULL && table->entryCount > 0) { + // add mods to activity + for (int i = 0; i < table->entryCount; i++) { + struct ModListEntry* entry = &table->entries[i]; + if (!entry->enabled) { continue; } + if (displayDash) { strncat(gCurActivity.details, " - ", 127); } + if (displayComma) { strncat(gCurActivity.details, ", ", 127); } + + strncat(gCurActivity.details, entry->displayName ? entry->displayName : entry->name, 127); + + displayDash = false; + displayComma = true; + } + } + } app.activities->update_activity(app.activities, &gCurActivity, NULL, on_activity_update_callback); diff --git a/src/pc/network/packets/packet_download.c b/src/pc/network/packets/packet_download.c index 61fbd59d8..c1180ab92 100644 --- a/src/pc/network/packets/packet_download.c +++ b/src/pc/network/packets/packet_download.c @@ -185,6 +185,12 @@ void network_receive_download(struct Packet* p) { if (sOffset[OFFSET_COUNT - 1] + CHUNK_SIZE >= entry->size) { LOG_INFO("Finished download of '%s'", entry->name); fclose(entry->fp); + + // parse mod header + entry->fp = fopen(entry->path, "rb"); + mod_list_extract_lua_fields(entry); + fclose(entry->fp); + entry->fp = NULL; entry->complete = true; } diff --git a/src/pc/network/packets/packet_mod_list.c b/src/pc/network/packets/packet_mod_list.c index bab8b58db..6be476bf5 100644 --- a/src/pc/network/packets/packet_mod_list.c +++ b/src/pc/network/packets/packet_mod_list.c @@ -91,6 +91,8 @@ void network_receive_mod_list(struct Packet* p) { } u16 modEntryCount = 0; + gModTableCurrent = &gModTableRemote; + packet_read(p, &modEntryCount, sizeof(u16)); mod_list_alloc(&gModTableRemote, modEntryCount);