From 9538c551e47e33a80780f0560383db7db4a460e6 Mon Sep 17 00:00:00 2001 From: MysterD Date: Mon, 21 Mar 2022 00:15:19 -0700 Subject: [PATCH] Lua Bugfix: send tables inside of sync tables on join --- src/pc/lua/smlua_sync_table.c | 21 +++++++++++-------- .../network/packets/packet_lua_sync_table.c | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/pc/lua/smlua_sync_table.c b/src/pc/lua/smlua_sync_table.c index 26365a1fd..aca81fbd1 100644 --- a/src/pc/lua/smlua_sync_table.c +++ b/src/pc/lua/smlua_sync_table.c @@ -261,7 +261,7 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al lua_pop(L, 1); // pop seq value // set seq number - if (!gLuaInitializingScript && alterSeq) { + if (alterSeq) { seq += MAX_PLAYERS + (MAX_PLAYERS - gNetworkPlayers[0].globalIndex); lua_pushvalue(L, keyIndex); lua_pushinteger(L, seq); @@ -282,7 +282,7 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al } // send over the network - if (!gLuaInitializingScript && seq > 0) { + if (!gLuaInitializingScript) { network_send_lua_sync_table(toLocalIndex, seq, modRemoteIndex, sUnwoundLntsCount, sUnwoundLnts, &lntValue); } @@ -513,14 +513,17 @@ static void smlua_sync_table_send_table(u8 toLocalIndex) { lua_pushnil(L); // first key while (lua_next(L, internalIndex) != 0) { // uses 'key' (at index -2) and 'value' (at index -1) - //LOG_INFO(" sending sync table field: %s", lua_tostring(L, -2)); - lua_pushvalue(L, tableIndex); // insert sync table - lua_insert(L, -3); // re-order sync table - - smlua_sync_table_send_field(toLocalIndex, internalIndex, false); - - lua_remove(L, -3); // remove sync table + if (lua_type(L, -1) == LUA_TTABLE) { + LOG_INFO(" sending sync table field (table): %s", lua_tostring(L, -2)); + smlua_sync_table_send_table(toLocalIndex); + } else { + LOG_INFO(" sending sync table field: %s", lua_tostring(L, -2)); + lua_pushvalue(L, tableIndex); // insert sync table + lua_insert(L, -3); // re-order sync table + smlua_sync_table_send_field(toLocalIndex, internalIndex, false); + lua_remove(L, -3); // remove sync table + } lua_pop(L, 1); // removed value ; keeps 'key' for next iteration } diff --git a/src/pc/network/packets/packet_lua_sync_table.c b/src/pc/network/packets/packet_lua_sync_table.c index 492cc1d1e..c1f304d2a 100644 --- a/src/pc/network/packets/packet_lua_sync_table.c +++ b/src/pc/network/packets/packet_lua_sync_table.c @@ -119,6 +119,7 @@ void network_send_lua_sync_table(u8 toLocalIndex, u64 seq, u16 modRemoteIndex, u packet_write(&p, &modRemoteIndex, sizeof(u16)); packet_write(&p, &lntKeyCount, sizeof(u16)); + for (int i = 0; i < lntKeyCount; i++) { if (!packet_write_lnt(&p, &lntKeys[i])) { return; } }