diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 9a4ce790..60959a1c 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -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; } diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c index 96c8e875..a660be99 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -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) { diff --git a/src/pc/lua/smlua_sync_table.c b/src/pc/lua/smlua_sync_table.c index 570aa448..c01a4dcd 100644 --- a/src/pc/lua/smlua_sync_table.c +++ b/src/pc/lua/smlua_sync_table.c @@ -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");