From 3f1c8db362e0d8cd83649af08f444075ce3254c3 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 17:33:17 +0200 Subject: [PATCH] some stuff i forgor --- src/lua_script.c | 77 ++++++++++++++++++++++++++---------------------- src/p_saveg.c | 8 ++--- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 2440be7ab..43553f381 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1125,7 +1125,7 @@ static UINT8 UnArchiveValueDemo(UINT8 **p, int TABLESINDEX, char field[1024]) return 0; } -static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean isdemo) +static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean network) { int TABLESINDEX; UINT16 field_count = READUINT16(*p); @@ -1144,13 +1144,13 @@ static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean isdemo) TABLESINDEX = lua_gettop(gL); lua_createtable(gL, 0, field_count); // pointer's ext vars subtable - if (isdemo) + if (network) { for (i = 0; i < field_count; i++) { READSTRING(*p, field); - if (UnArchiveValueDemo(p, TABLESINDEX, field) != 3) // This will return 3 if we shouldn't set this field. - lua_setfield(gL, -2, field); + UnArchiveValue(p, TABLESINDEX); + lua_setfield(gL, -2, field); } } else @@ -1158,8 +1158,8 @@ static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean isdemo) for (i = 0; i < field_count; i++) { READSTRING(*p, field); - UnArchiveValue(p, TABLESINDEX); - lua_setfield(gL, -2, field); + if (UnArchiveValueDemo(p, TABLESINDEX, field) != 3) // This will return 3 if we shouldn't set this field. + lua_setfield(gL, -2, field); } } @@ -1181,7 +1181,7 @@ static int NetUnArchive(lua_State *L) return n; } -static void UnArchiveTables(UINT8 **p, boolean isdemo) +static void UnArchiveTables(UINT8 **p, boolean network) { int TABLESINDEX; UINT16 i, n; @@ -1192,7 +1192,30 @@ static void UnArchiveTables(UINT8 **p, boolean isdemo) TABLESINDEX = lua_gettop(gL); n = (UINT16)lua_objlen(gL, TABLESINDEX); - if (isdemo) + + if (network) + { + for (i = 1; i <= n; i++) + { + lua_rawgeti(gL, TABLESINDEX, i); + while (true) + { + if (UnArchiveValue(p, TABLESINDEX) == 1) // read key + break; + if (UnArchiveValue(p, TABLESINDEX) == 2) // read value + n++; + if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) + { + CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); + lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors + } + else + lua_rawset(gL, -3); + } + lua_pop(gL, 1); + } + } + else { for (i = 1; i <= n; i++) { @@ -1225,28 +1248,7 @@ static void UnArchiveTables(UINT8 **p, boolean isdemo) lua_pop(gL, 1); } } - else - { - for (i = 1; i <= n; i++) - { - lua_rawgeti(gL, TABLESINDEX, i); - while (true) - { - if (UnArchiveValue(p, TABLESINDEX) == 1) // read key - break; - if (UnArchiveValue(p, TABLESINDEX) == 2) // read value - n++; - if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) - { - CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); - lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors - } - else - lua_rawset(gL, -3); - } - lua_pop(gL, 1); - } - } + } void LUA_Step(void) @@ -1311,7 +1313,8 @@ void LUA_UnArchive(savebuffer_t *save, boolean network) { if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. continue; - UnArchiveExtVars(&save->p, &players[i], !network); + + UnArchiveExtVars(&save->p, &players[i], network); } if (network == true) @@ -1319,15 +1322,19 @@ void LUA_UnArchive(savebuffer_t *save, boolean network) do { mobjnum = READUINT32(save->p); // read a mobjnum for (th = thinkercap.next; th != &thinkercap; th = th->next) - if (th->function.acp1 == (actionf_p1)P_MobjThinker - && ((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj - UnArchiveExtVars(&save->p, th, !network); // apply variables + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + if (((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj + UnArchiveExtVars(&save->p, th, network); // apply variables + } } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. LUAh_NetArchiveHook(NetUnArchive, save); // call the NetArchive hook in unarchive mode } - UnArchiveTables(&save->p, !network); + UnArchiveTables(&save->p, network); if (gL) lua_pop(gL, 1); // pop tables diff --git a/src/p_saveg.c b/src/p_saveg.c index e3a1f1f6d..e7f447762 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -67,7 +67,7 @@ static inline void P_ArchivePlayer(savebuffer_t *save) pllives = 3; // has less than that. WRITEUINT8(save->p, player->skincolor); - WRITEUINT16(save->p, player->skin); + WRITEUINT8(save->p, player->skin); WRITEUINT32(save->p, player->score); WRITEINT32(save->p, pllives); @@ -75,7 +75,7 @@ static inline void P_ArchivePlayer(savebuffer_t *save) if (botskin) { - WRITEUINT16(save->p, botskin); + WRITEUINT8(save->p, botskin); WRITEUINT8(save->p, botcolor); } } @@ -86,7 +86,7 @@ static inline void P_ArchivePlayer(savebuffer_t *save) static inline void P_UnArchivePlayer(savebuffer_t *save) { savedata.skincolor = READUINT8(save->p); - savedata.skin = READUINT16(save->p); + savedata.skin = READUINT8(save->p); savedata.score = READINT32(save->p); savedata.lives = READINT32(save->p); @@ -94,7 +94,7 @@ static inline void P_UnArchivePlayer(savebuffer_t *save) if (savedata.botcolor) { - savedata.botskin = READUINT16(save->p); + savedata.botskin = READUINT8(save->p); if (savedata.botskin-1 >= numskins) savedata.botskin = 0; savedata.botcolor = READUINT8(save->p);