mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-26 20:11:42 +00:00
Transitioned Lua to new mod table system
This commit is contained in:
parent
0983474429
commit
f880784f8e
14 changed files with 138 additions and 134 deletions
|
|
@ -26,7 +26,7 @@
|
|||
#include "src/pc/djui/djui.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/gfx/gfx_rendering_api.h"
|
||||
#include "pc/mod_list.h"
|
||||
#include "pc/mods/mods.h"
|
||||
#include "dbghelp.h"
|
||||
|
||||
#if IS_64_BIT
|
||||
|
|
@ -451,8 +451,9 @@ static CRASH_HANDLER_TYPE crash_handler(EXCEPTION_POINTERS *ExceptionInfo) {
|
|||
crash_handler_add_info_int(&pText, 315, -4 + (8 * 4), "Objs", gPrevFrameObjectCount);
|
||||
|
||||
int modCount = 0;
|
||||
for (int i = 0; i < gModTableCurrent->entryCount; i++) {
|
||||
if (gModTableCurrent->entries[i].enabled) { modCount++; }
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (mod->enabled) { modCount++; }
|
||||
}
|
||||
crash_handler_add_info_int(&pText, 380, -4 + (8 * 2), "Mods", modCount);
|
||||
|
||||
|
|
@ -461,11 +462,11 @@ static CRASH_HANDLER_TYPE crash_handler(EXCEPTION_POINTERS *ExceptionInfo) {
|
|||
{
|
||||
int x = 245;
|
||||
int y = 72;
|
||||
for (int i = 0; i < gModTableCurrent->entryCount; i++) {
|
||||
struct ModListEntry* entry = &gModTableCurrent->entries[i];
|
||||
if (entry == NULL || !entry->enabled) { continue; }
|
||||
u8 g = (gPcDebug.lastModRun == entry) ? 0 : 0xFF;
|
||||
crash_handler_set_text(x, y, 0xFF, g, 200, "%.21s", entry->name);
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (mod == NULL || !mod->enabled) { continue; }
|
||||
u8 g = (gPcDebug.lastModRun == mod) ? 0 : 0xFF;
|
||||
crash_handler_set_text(x, y, 0xFF, g, 200, "%.21s", mod->name);
|
||||
y += 8;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "djui.h"
|
||||
#include "pc/mod_list.h"
|
||||
#include "pc/mods/mods.h"
|
||||
|
||||
struct DjuiThreePanel* gDjuiModList = NULL;
|
||||
|
||||
|
|
@ -17,9 +17,9 @@ void djui_panel_modlist_create(UNUSED struct DjuiBase* caller) {
|
|||
|
||||
// count mods
|
||||
int enabledCount = 0;
|
||||
for (int i = 0; i < gModTableCurrent->entryCount; i++) {
|
||||
struct ModListEntry* entry = &gModTableCurrent->entries[i];
|
||||
if (!entry->enabled) { continue; }
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (!mod->enabled) { continue; }
|
||||
enabledCount++;
|
||||
}
|
||||
|
||||
|
|
@ -42,9 +42,9 @@ void djui_panel_modlist_create(UNUSED struct DjuiBase* caller) {
|
|||
struct DjuiFlowLayout* body = (struct DjuiFlowLayout*)djui_three_panel_get_body(panel);
|
||||
djui_flow_layout_set_margin(body, 4);
|
||||
|
||||
for (int i = 0; i < gModTableCurrent->entryCount; i++) {
|
||||
struct ModListEntry* entry = &gModTableCurrent->entries[i];
|
||||
if (!entry->enabled) { continue; }
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (!mod->enabled) { continue; }
|
||||
|
||||
struct DjuiFlowLayout* row = djui_flow_layout_create(&body->base);
|
||||
djui_base_set_size_type(&row->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
|
|
@ -55,7 +55,7 @@ void djui_panel_modlist_create(UNUSED struct DjuiBase* caller) {
|
|||
djui_flow_layout_set_margin(row, 8);
|
||||
|
||||
int t = 220;
|
||||
struct DjuiText* t2 = djui_text_create(&row->base, entry->displayName ? entry->displayName : entry->name);
|
||||
struct DjuiText* t2 = djui_text_create(&row->base, mod->name);
|
||||
djui_base_set_size_type(&t2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&t2->base, 1.0f, 32.0f);
|
||||
djui_base_set_color(&t2->base, t, t, t, 255);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
#include "smlua.h"
|
||||
#include "pc/mod_list.h"
|
||||
#include "pc/mods/mods.h"
|
||||
#include "pc/mods/mods_utils.h"
|
||||
#include "pc/crash_handler.h"
|
||||
|
||||
lua_State* gLuaState = NULL;
|
||||
u8 gLuaInitializingScript = 0;
|
||||
struct ModListEntry* gLuaLoadingEntry = NULL;
|
||||
struct ModListEntry* gLuaActiveEntry = NULL;
|
||||
struct Mod* gLuaLoadingMod = NULL;
|
||||
struct Mod* gLuaActiveMod = NULL;
|
||||
|
||||
static void smlua_exec_file(char* path) {
|
||||
lua_State* L = gLuaState;
|
||||
|
|
@ -25,35 +26,54 @@ static void smlua_exec_str(char* str) {
|
|||
lua_pop(L, lua_gettop(L));
|
||||
}
|
||||
|
||||
static void smlua_load_script(char* path, u16 remoteIndex) {
|
||||
static void smlua_load_script(struct Mod* mod, struct ModFile* file, u16 remoteIndex) {
|
||||
lua_State* L = gLuaState;
|
||||
|
||||
char fullPath[SYS_MAX_PATH] = { 0 };
|
||||
if (!mod_file_full_path(fullPath, mod, file)) {
|
||||
LOG_ERROR("Failed to concat path: '%s' + '%s", mod->relativePath, file->relativePath);
|
||||
return;
|
||||
}
|
||||
|
||||
gLuaInitializingScript = 1;
|
||||
if (luaL_loadfile(L, path) != LUA_OK) {
|
||||
LOG_LUA("Failed to load lua script '%s'.", path);
|
||||
if (luaL_loadfile(L, fullPath) != LUA_OK) {
|
||||
LOG_LUA("Failed to load lua script '%s'.", fullPath);
|
||||
puts(smlua_to_string(L, lua_gettop(L)));
|
||||
return;
|
||||
}
|
||||
|
||||
lua_newtable(L); // create _ENV tables
|
||||
lua_newtable(L); // create metatable
|
||||
lua_getglobal(L, "_G"); // get global table
|
||||
// check if this is the first time this mod has been loaded
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, mod->relativePath);
|
||||
bool firstInit = (lua_type(L, -1) == LUA_TNIL);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// set global as the metatable
|
||||
lua_setfield(L, -2, "__index");
|
||||
lua_setmetatable(L, -2);
|
||||
// create mod's "global" table
|
||||
if (firstInit) {
|
||||
lua_newtable(L); // create _ENV tables
|
||||
lua_newtable(L); // create metatable
|
||||
lua_getglobal(L, "_G"); // get global table
|
||||
|
||||
// push to registry with path as name (must be unique)
|
||||
lua_setfield(L, LUA_REGISTRYINDEX, path);
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, path);
|
||||
// set global as the metatable
|
||||
lua_setfield(L, -2, "__index");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
// push to registry with path as name (must be unique)
|
||||
lua_setfield(L, LUA_REGISTRYINDEX, mod->relativePath);
|
||||
}
|
||||
|
||||
// load mod's "global" table
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, mod->relativePath);
|
||||
lua_setupvalue(L, 1, 1); // set upvalue (_ENV)
|
||||
|
||||
// load per-file globals
|
||||
smlua_sync_table_init_globals(path, remoteIndex);
|
||||
smlua_cobject_init_per_file_globals(path);
|
||||
if (firstInit) {
|
||||
smlua_sync_table_init_globals(mod->relativePath, remoteIndex);
|
||||
smlua_cobject_init_per_file_globals(mod->relativePath);
|
||||
}
|
||||
|
||||
// run chunks
|
||||
if (lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK) {
|
||||
LOG_LUA("Failed to execute lua script '%s'.", path);
|
||||
LOG_LUA("Failed to execute lua script '%s'.", fullPath);
|
||||
puts(smlua_to_string(L, lua_gettop(L)));
|
||||
smlua_dump_stack();
|
||||
gLuaInitializingScript = 0;
|
||||
|
|
@ -94,19 +114,24 @@ void smlua_init(void) {
|
|||
smlua_cobject_init_globals();
|
||||
|
||||
// load scripts
|
||||
mod_list_size_enforce();
|
||||
mods_size_enforce(&gActiveMods);
|
||||
LOG_INFO("Loading scripts:");
|
||||
struct ModTable* table = gModTableCurrent;
|
||||
for (int i = 0; i < table->entryCount; i++) {
|
||||
struct ModListEntry* entry = &table->entries[i];
|
||||
if (!entry->enabled) { continue; }
|
||||
LOG_INFO(" %s", entry->path);
|
||||
gLuaLoadingEntry = entry;
|
||||
gLuaActiveEntry = entry;
|
||||
gPcDebug.lastModRun = gLuaActiveEntry;
|
||||
smlua_load_script(entry->path, entry->remoteIndex);
|
||||
gLuaActiveEntry = NULL;
|
||||
gLuaLoadingEntry = NULL;
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (!mod->enabled) { continue; }
|
||||
LOG_INFO(" %s", mod->relativePath);
|
||||
gLuaLoadingMod = mod;
|
||||
gLuaActiveMod = mod;
|
||||
gPcDebug.lastModRun = gLuaActiveMod;
|
||||
for (int j = 0; j < mod->fileCount; j++) {
|
||||
struct ModFile* file = &mod->files[j];
|
||||
if (!str_ends_with(file->relativePath, ".lua")) {
|
||||
continue;
|
||||
}
|
||||
smlua_load_script(mod, file, i);
|
||||
}
|
||||
gLuaActiveMod = NULL;
|
||||
gLuaLoadingMod = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
|
||||
extern lua_State* gLuaState;
|
||||
extern u8 gLuaInitializingScript;
|
||||
extern struct ModListEntry* gLuaLoadingEntry;
|
||||
extern struct ModListEntry* gLuaActiveEntry;
|
||||
extern struct Mod* gLuaLoadingMod;
|
||||
extern struct Mod* gLuaActiveMod;
|
||||
|
||||
void smlua_init(void);
|
||||
void smlua_update(void);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include "pc/lua/smlua.h"
|
||||
#include "pc/lua/utils/smlua_anim_utils.h"
|
||||
#include "pc/lua/utils/smlua_collision_utils.h"
|
||||
#include "pc/mod_list.h"
|
||||
#include "pc/mods/mods.h"
|
||||
|
||||
#define LUA_VEC3S_FIELD_COUNT 3
|
||||
static struct LuaObjectField sVec3sFields[LUA_VEC3S_FIELD_COUNT] = {
|
||||
|
|
@ -85,14 +85,14 @@ static int smlua_func_define_custom_obj_fields(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (gLuaLoadingEntry == NULL) {
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("define_custom_obj_fields() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get _custom_object_fields
|
||||
lua_getglobal(L, "_G"); // get global table
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, gLuaLoadingEntry->path); // push file's "global" table
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, gLuaLoadingMod->relativePath); // push file's "global" table
|
||||
int fileGlobalIndex = lua_gettop(L);
|
||||
lua_getfield(L, fileGlobalIndex, "_custom_object_fields");
|
||||
lua_remove(L, -2); // remove file's "global" table
|
||||
|
|
@ -180,14 +180,14 @@ struct LuaObjectField* smlua_get_custom_field(lua_State* L, u32 lot, int keyInde
|
|||
static struct LuaObjectField lof = { 0 };
|
||||
if (lot != LOT_OBJECT) { return NULL; }
|
||||
|
||||
if (gLuaActiveEntry == NULL) {
|
||||
if (gLuaActiveMod == NULL) {
|
||||
LOG_LUA("Failed to retrieve active mod entry.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// get _custom_object_fields
|
||||
lua_getglobal(L, "_G"); // get global table
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, gLuaActiveEntry->path); // push file's "global" table
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, gLuaActiveMod->relativePath); // push file's "global" table
|
||||
int fileGlobalIndex = lua_gettop(L);
|
||||
lua_getfield(L, fileGlobalIndex, "_custom_object_fields");
|
||||
lua_remove(L, -2); // remove file's "global" table
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@ static u64* sBehaviorOffset = &gPcDebug.bhvOffset;
|
|||
|
||||
struct LuaHookedEvent {
|
||||
int reference[MAX_HOOKED_REFERENCES];
|
||||
struct ModListEntry* entry[MAX_HOOKED_REFERENCES];
|
||||
struct Mod* mod[MAX_HOOKED_REFERENCES];
|
||||
int count;
|
||||
};
|
||||
|
||||
static struct LuaHookedEvent sHookedEvents[HOOK_MAX] = { 0 };
|
||||
|
||||
static int smlua_call_hook(lua_State* L, int nargs, int nresults, int errfunc, struct ModListEntry* activeEntry) {
|
||||
struct ModListEntry* prev = gLuaActiveEntry;
|
||||
gLuaActiveEntry = activeEntry;
|
||||
static int smlua_call_hook(lua_State* L, int nargs, int nresults, int errfunc, struct Mod* activeMod) {
|
||||
struct Mod* prev = gLuaActiveMod;
|
||||
gLuaActiveMod = activeMod;
|
||||
int rc = lua_pcall(L, nargs, nresults, errfunc);
|
||||
gLuaActiveEntry = prev;
|
||||
gLuaActiveMod = prev;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ int smlua_hook_event(lua_State* L) {
|
|||
}
|
||||
|
||||
hook->reference[hook->count] = ref;
|
||||
hook->entry[hook->count] = gLuaActiveEntry;
|
||||
hook->mod[hook->count] = gLuaActiveMod;
|
||||
hook->count++;
|
||||
|
||||
return 1;
|
||||
|
|
@ -67,7 +67,7 @@ void smlua_call_event_hooks(enum LuaHookedEventType hookType) {
|
|||
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 0, 0, 0, hook->entry[i])) {
|
||||
if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the event_hook callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
|
|
@ -90,7 +90,7 @@ void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct
|
|||
lua_remove(L, -2);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->entry[i])) {
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
|
|
@ -119,7 +119,7 @@ void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struc
|
|||
lua_remove(L, -2);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 2, 0, 0, hook->entry[i])) {
|
||||
if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
|
|
@ -148,7 +148,7 @@ void smlua_call_event_hooks_mario_params_ret_bool(enum LuaHookedEventType hookTy
|
|||
lua_remove(L, -2);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 2, 1, 0, hook->entry[i])) {
|
||||
if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
|
|
@ -184,7 +184,7 @@ void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, st
|
|||
lua_pushboolean(L, interactValue);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 4, 0, 0, hook->entry[i])) {
|
||||
if (0 != smlua_call_hook(L, 4, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
|
|
@ -207,7 +207,7 @@ void smlua_call_event_hooks_network_player_param(enum LuaHookedEventType hookTyp
|
|||
lua_remove(L, -2);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->entry[i])) {
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
|
|
@ -223,7 +223,7 @@ struct LuaHookedMarioAction {
|
|||
u32 action;
|
||||
u32 interactionType;
|
||||
int reference;
|
||||
struct ModListEntry* entry;
|
||||
struct Mod* mod;
|
||||
};
|
||||
|
||||
#define MAX_HOOKED_ACTIONS 128
|
||||
|
|
@ -235,7 +235,7 @@ int smlua_hook_mario_action(lua_State* L) {
|
|||
if (L == NULL) { return 0; }
|
||||
if (!smlua_functions_valid_param_range(L, 2, 3)) { return 0; }
|
||||
|
||||
if (gLuaLoadingEntry == NULL) {
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("hook_mario_action() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -278,7 +278,7 @@ int smlua_hook_mario_action(lua_State* L) {
|
|||
hooked->action = action;
|
||||
hooked->interactionType = interactionType;
|
||||
hooked->reference = ref;
|
||||
hooked->entry = gLuaActiveEntry;
|
||||
hooked->mod = gLuaActiveMod;
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
sHookedMarioActionsCount++;
|
||||
|
|
@ -301,7 +301,7 @@ bool smlua_call_action_hook(struct MarioState* m, s32* returnValue) {
|
|||
lua_remove(L, -2);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 1, 0, hook->entry)) {
|
||||
if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod)) {
|
||||
LOG_LUA("Failed to call the action callback: %u, %s", m->action, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
|
|
@ -344,7 +344,7 @@ struct LuaHookedBehavior {
|
|||
int initReference;
|
||||
int loopReference;
|
||||
bool replace;
|
||||
struct ModListEntry* entry;
|
||||
struct Mod* mod;
|
||||
};
|
||||
|
||||
#define MAX_HOOKED_BEHAVIORS 256
|
||||
|
|
@ -378,7 +378,7 @@ int smlua_hook_behavior(lua_State* L) {
|
|||
if (L == NULL) { return 0; }
|
||||
if (!smlua_functions_valid_param_count(L, 5)) { return 0; }
|
||||
|
||||
if (gLuaLoadingEntry == NULL) {
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("hook_behavior() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -454,7 +454,7 @@ int smlua_hook_behavior(lua_State* L) {
|
|||
hooked->initReference = initReference;
|
||||
hooked->loopReference = loopReference;
|
||||
hooked->replace = replaceBehavior;
|
||||
hooked->entry = gLuaActiveEntry;
|
||||
hooked->mod = gLuaActiveMod;
|
||||
|
||||
sHookedBehaviorsCount++;
|
||||
|
||||
|
|
@ -500,7 +500,7 @@ bool smlua_call_behavior_hook(const BehaviorScript** behavior, struct Object* ob
|
|||
smlua_push_object(L, LOT_OBJECT, object);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hooked->entry)) {
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hooked->mod)) {
|
||||
LOG_LUA("Failed to call the behavior callback: %u, %s", hooked->behaviorId, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
return true;
|
||||
|
|
@ -521,7 +521,7 @@ struct LuaHookedChatCommand {
|
|||
char* command;
|
||||
char* description;
|
||||
int reference;
|
||||
struct ModListEntry* entry;
|
||||
struct Mod* mod;
|
||||
};
|
||||
|
||||
#define MAX_HOOKED_CHAT_COMMANDS 64
|
||||
|
|
@ -533,7 +533,7 @@ int smlua_hook_chat_command(lua_State* L) {
|
|||
if (L == NULL) { return 0; }
|
||||
if (!smlua_functions_valid_param_count(L, 3)) { return 0; }
|
||||
|
||||
if (gLuaLoadingEntry == NULL) {
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("hook_chat_command() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -569,7 +569,7 @@ int smlua_hook_chat_command(lua_State* L) {
|
|||
hooked->command = strdup(command);
|
||||
hooked->description = strdup(description);
|
||||
hooked->reference = ref;
|
||||
hooked->entry = gLuaActiveEntry;
|
||||
hooked->mod = gLuaActiveMod;
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
sHookedChatCommandsCount++;
|
||||
|
|
@ -603,7 +603,7 @@ bool smlua_call_chat_command_hook(char* command) {
|
|||
lua_pushstring(L, params);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 1, 0, hook->entry)) {
|
||||
if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod)) {
|
||||
LOG_LUA("Failed to call the chat command callback: %s, %s", command, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
|
|
@ -647,7 +647,7 @@ int smlua_hook_on_sync_table_change(lua_State* L) {
|
|||
int tagIndex = 3;
|
||||
int funcIndex = 4;
|
||||
|
||||
if (gLuaLoadingEntry == NULL) {
|
||||
if (gLuaLoadingMod == NULL) {
|
||||
LOG_LUA("hook_on_sync_table_change() can only be called on load.");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -704,7 +704,7 @@ static void smlua_clear_hooks(void) {
|
|||
struct LuaHookedEvent* hooked = &sHookedEvents[i];
|
||||
for (int j = 0; j < hooked->count; j++) {
|
||||
hooked->reference[j] = 0;
|
||||
hooked->entry[j] = NULL;
|
||||
hooked->mod[j] = NULL;
|
||||
}
|
||||
hooked->count = 0;
|
||||
}
|
||||
|
|
@ -712,7 +712,7 @@ static void smlua_clear_hooks(void) {
|
|||
for (int i = 0; i < sHookedMarioActionsCount; i++) {
|
||||
struct LuaHookedMarioAction* hooked = &sHookedMarioActions[i];
|
||||
hooked->action = 0;
|
||||
hooked->entry = NULL;
|
||||
hooked->mod = NULL;
|
||||
hooked->reference = 0;
|
||||
}
|
||||
sHookedMarioActionsCount = 0;
|
||||
|
|
@ -726,7 +726,7 @@ static void smlua_clear_hooks(void) {
|
|||
hooked->description = NULL;
|
||||
|
||||
hooked->reference = 0;
|
||||
hooked->entry = NULL;
|
||||
hooked->mod = NULL;
|
||||
}
|
||||
sHookedChatCommandsCount = 0;
|
||||
|
||||
|
|
@ -739,7 +739,7 @@ static void smlua_clear_hooks(void) {
|
|||
hooked->initReference = 0;
|
||||
hooked->loopReference = 0;
|
||||
hooked->replace = false;
|
||||
hooked->entry = NULL;
|
||||
hooked->mod = NULL;
|
||||
}
|
||||
sHookedBehaviorsCount = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "smlua.h"
|
||||
#include "pc/crash_handler.h"
|
||||
#include "pc/mod_list.h"
|
||||
#include "pc/mods/mods.h"
|
||||
#include "pc/network/network.h"
|
||||
|
||||
#define MAX_UNWOUND_SIZE 256
|
||||
|
|
@ -140,25 +140,17 @@ static void smlua_sync_table_call_hook(int syncTableIndex, int keyIndex, int pre
|
|||
|
||||
// get entry
|
||||
u16 modRemoteIndex = smlua_get_integer_field(syncTableIndex, "_remoteIndex");
|
||||
struct ModListEntry* setEntry = NULL;
|
||||
for (int i = 0; i < gModTableCurrent->entryCount; i++) {
|
||||
struct ModListEntry* entry = &gModTableCurrent->entries[i];
|
||||
if (!entry->enabled) { continue; }
|
||||
if (entry->remoteIndex == modRemoteIndex) {
|
||||
setEntry = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
struct Mod* mod = gActiveMods.entries[modRemoteIndex];
|
||||
|
||||
// call hook
|
||||
struct ModListEntry* prev = gLuaActiveEntry;
|
||||
gLuaActiveEntry = setEntry;
|
||||
gPcDebug.lastModRun = gLuaActiveEntry;
|
||||
struct Mod* prev = gLuaActiveMod;
|
||||
gLuaActiveMod = mod;
|
||||
gPcDebug.lastModRun = gLuaActiveMod;
|
||||
if (0 != lua_pcall(L, 3, 0, 0)) {
|
||||
LOG_LUA("Failed to call the hook_on_changed callback: %s", lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
}
|
||||
gLuaActiveEntry = prev;
|
||||
gLuaActiveMod = prev;
|
||||
}
|
||||
|
||||
lua_pop(L, 1); // pop _hook_on_changed's value
|
||||
|
|
@ -318,26 +310,9 @@ void smlua_set_sync_table_field_from_network(u64 seq, u16 modRemoteIndex, u16 ln
|
|||
LUA_STACK_CHECK_BEGIN();
|
||||
lua_State* L = gLuaState;
|
||||
|
||||
// figure out mod table
|
||||
struct ModTable* table = NULL;
|
||||
if (gNetworkType == NT_SERVER) {
|
||||
table = &gModTableLocal;
|
||||
} else if (gNetworkType == NT_CLIENT) {
|
||||
table = &gModTableRemote;
|
||||
} else {
|
||||
LOG_ERROR("Received sync table field packet with an unknown network type: %d", gNetworkType);
|
||||
return;
|
||||
}
|
||||
|
||||
// figure out entry
|
||||
struct ModListEntry* entry = NULL;
|
||||
for (int i = 0; i < table->entryCount; i++) {
|
||||
if (table->entries[i].remoteIndex == modRemoteIndex) {
|
||||
entry = &table->entries[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entry == NULL) {
|
||||
struct Mod* mod = gActiveMods.entries[modRemoteIndex];
|
||||
if (mod == NULL) {
|
||||
LOG_ERROR("Could not find mod list entry for modRemoteIndex: %u", modRemoteIndex);
|
||||
return;
|
||||
}
|
||||
|
|
@ -349,7 +324,7 @@ void smlua_set_sync_table_field_from_network(u64 seq, u16 modRemoteIndex, u16 ln
|
|||
}
|
||||
|
||||
lua_getglobal(L, "_G"); // get global table
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, entry->path); // get the file's "global" table
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, mod->relativePath); // get the file's "global" table
|
||||
lua_remove(L, -2); // remove global table
|
||||
int fileGlobalIndex = lua_gettop(L);
|
||||
|
||||
|
|
@ -591,10 +566,10 @@ static void smlua_sync_table_send_all_file(u8 toLocalIndex, const char* path) {
|
|||
void smlua_sync_table_send_all(u8 toLocalIndex) {
|
||||
SOFT_ASSERT(gNetworkType == NT_SERVER);
|
||||
LUA_STACK_CHECK_BEGIN();
|
||||
for (int i = 0; i < gModTableLocal.entryCount; i++) {
|
||||
struct ModListEntry* entry = &gModTableLocal.entries[i];
|
||||
if (!entry->enabled) { continue; }
|
||||
smlua_sync_table_send_all_file(toLocalIndex, entry->path);
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (!mod->enabled) { continue; }
|
||||
smlua_sync_table_send_all_file(toLocalIndex, mod->relativePath);
|
||||
}
|
||||
LUA_STACK_CHECK_END();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ void mods_activate(struct Mods* mods) {
|
|||
|
||||
char fullPath[SYS_MAX_PATH] = { 0 };
|
||||
if (!mod_file_full_path(fullPath, mod, file)) {
|
||||
LOG_ERROR("Failed to concat path: '%s' + '%s'", mod->basePath, relativePath);
|
||||
LOG_ERROR("Failed to concat path: '%s' + '%s'", mod->basePath, file->relativePath);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ extern struct Mods gLocalMods;
|
|||
extern struct Mods gRemoteMods;
|
||||
extern struct Mods gActiveMods;
|
||||
|
||||
void mods_activate(struct Mods* mods);
|
||||
void mods_clear(struct Mods* mods);
|
||||
void mods_init(void);
|
||||
void mods_shutdown(void);
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
#include "mods_utils.h"
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
void mods_size_enforce(void) {
|
||||
for (int i = 0; i < gLocalMods.entryCount; i++) {
|
||||
struct Mod* mod = gLocalMods.entries[i];
|
||||
void mods_size_enforce(struct Mods* mods) {
|
||||
for (int i = 0; i < mods->entryCount; i++) {
|
||||
struct Mod* mod = mods->entries[i];
|
||||
if (mod->size >= MAX_MOD_SIZE) {
|
||||
mod->enabled = false;
|
||||
mod->selectable = false;
|
||||
|
|
@ -64,7 +64,7 @@ void mods_update_selectable(void) {
|
|||
}
|
||||
}
|
||||
|
||||
mods_size_enforce();
|
||||
mods_size_enforce(&gLocalMods);
|
||||
}
|
||||
|
||||
bool mod_file_full_path(char* destination, struct Mod* mod, struct ModFile* modFile) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <types.h>
|
||||
#include "src/pc/platform.h"
|
||||
|
||||
void mods_size_enforce(void);
|
||||
void mods_size_enforce(struct Mods* mods);
|
||||
void mods_update_selectable(void);
|
||||
bool mod_file_full_path(char* destination, struct Mod* mod, struct ModFile* modFile);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include "pc/network/network.h"
|
||||
#include "pc/network/version.h"
|
||||
#include "pc/djui/djui.h"
|
||||
#include "pc/mod_list.h"
|
||||
#include "pc/mods/mods.h"
|
||||
#include "pc/logfile.h"
|
||||
|
||||
#define HASH_LENGTH 8
|
||||
|
|
@ -95,16 +95,15 @@ static bool discord_populate_details(char* details, bool shorten) {
|
|||
}
|
||||
}
|
||||
|
||||
struct ModTable* table = gModTableCurrent;
|
||||
if (table != NULL && table->entryCount > 0) {
|
||||
if (gActiveMods.entryCount > 0) {
|
||||
// add mods to activity
|
||||
for (int i = 0; i < table->entryCount; i++) {
|
||||
struct ModListEntry* entry = &table->entries[i];
|
||||
if (!entry->enabled) { continue; }
|
||||
for (int i = 0; i < gActiveMods.entryCount; i++) {
|
||||
struct Mod* mod = gActiveMods.entries[i];
|
||||
if (!mod->enabled) { continue; }
|
||||
if (displayDash) { strncat_len(details, " - ", 127, catLength); }
|
||||
if (displayComma) { strncat_len(details, ", ", 127, catLength); }
|
||||
|
||||
strncat_len(details, entry->displayName ? entry->displayName : entry->name, 127, catLength);
|
||||
strncat_len(details, mod->name, 127, catLength);
|
||||
|
||||
displayDash = false;
|
||||
displayComma = true;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include "pc/djui/djui.h"
|
||||
#include "pc/utils/misc.h"
|
||||
#include "pc/lua/smlua.h"
|
||||
#include "pc/mod_list.h"
|
||||
#include "pc/mods/mods.h"
|
||||
#include "pc/crash_handler.h"
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
|
|
@ -109,6 +109,7 @@ bool network_init(enum NetworkType inNetworkType) {
|
|||
gNetworkType = inNetworkType;
|
||||
|
||||
if (gNetworkType == NT_SERVER) {
|
||||
mods_activate(&gLocalMods);
|
||||
smlua_init();
|
||||
|
||||
network_player_connected(NPT_LOCAL, 0, configPlayerModel, configPlayerPalette, configPlayerName);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
#include "pc/utils/misc.h"
|
||||
#include "pc/mods/mods.h"
|
||||
#include "pc/lua/smlua.h"
|
||||
#include "pc/configfile.h"
|
||||
|
||||
|
|
@ -231,6 +232,7 @@ void network_receive_join(struct Packet* p) {
|
|||
extern s16 gChangeLevel;
|
||||
gChangeLevel = 16;
|
||||
|
||||
mods_activate(&gRemoteMods);
|
||||
smlua_init();
|
||||
|
||||
network_send_network_players_request();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue