Prevent broken mods from messing up the sync table of others

This commit is contained in:
MysterD 2023-05-16 23:53:12 -07:00
parent 2dde74b4b6
commit 93020c04e5
3 changed files with 14 additions and 9 deletions

View File

@ -1025,10 +1025,6 @@ static void level_cmd_load_model_from_geo_ext(void) {
s16 modelSlot = CMD_GET(s16, 2);
const char* geoName = dynos_level_get_token(CMD_GET(u32, 4));
smlua_model_util_store_in_slot(modelSlot, geoName);
// DO NOT COMMIT, this is broken
// it's supposed to load our custom model into a vanilla slot (ugh why)
sCurrentCmd = CMD_NEXT;
}

View File

@ -72,11 +72,7 @@ static void smlua_load_script(struct Mod* mod, struct ModFile* file, u16 remoteI
gSmLuaConvertSuccess = true;
gLuaInitializingScript = 1;
LOG_INFO("Loading lua script '%s'", file->cachedPath);
if (luaL_loadfile(L, file->cachedPath) != LUA_OK) {
LOG_LUA("Failed to load lua script '%s'.", file->cachedPath);
LOG_LUA("%s", smlua_to_string(L, lua_gettop(L)));
return;
}
bool failed = (luaL_loadfile(L, file->cachedPath) != LUA_OK);
// check if this is the first time this mod has been loaded
lua_getfield(L, LUA_REGISTRYINDEX, mod->relativePath);
@ -114,6 +110,14 @@ static void smlua_load_script(struct Mod* mod, struct ModFile* file, u16 remoteI
smlua_cobject_init_per_file_globals(mod->relativePath);
}
// only run on success
if (failed) {
LOG_LUA("Failed to load lua script '%s'.", file->cachedPath);
LOG_LUA("%s", smlua_to_string(L, lua_gettop(L)));
gLuaInitializingScript = 0;
return;
}
// run chunks
LOG_INFO("Executing '%s'", file->relativePath);
if (smlua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK) {

View File

@ -525,6 +525,11 @@ static void smlua_sync_table_send_all_file(u8 toLocalIndex, const char* path) {
LOG_INFO("sending sync table for file %s to %u", path, toLocalIndex);
lua_getfield(L, LUA_REGISTRYINDEX, path); // get the file's "global" table
if (lua_type(L, -1) == LUA_TNIL) {
LOG_ERROR("Could not find table for '%s'", path);
lua_pop(L, 1);
return;
}
{
lua_getfield(L, -1, "gGlobalSyncTable");