diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 21fd66e97..8ad22558e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -6441,8 +6441,9 @@ static void Command_Archivetest_f(void) } // test archive - CONS_Printf("LUA_Archive...\n"); - LUA_Archive(&save, true); + CONS_Printf("LUA_Sync Archive...\n"); + save.write = true; + LUA_Sync(&save, true, false); WRITEUINT8(save.p, 0x7F); wrote = (UINT32)(save.p - save.buffer); @@ -6452,8 +6453,9 @@ static void Command_Archivetest_f(void) // test unarchive save.p = save.buffer; - CONS_Printf("LUA_UnArchive...\n"); - LUA_UnArchive(&save, true, false); + save.write = false; + CONS_Printf("LUA_Sync Unarchive...\n"); + LUA_Sync(&save, true, false); i = READUINT8(save.p); if (i != 0x7F || wrote != (UINT32)(save.p - save.buffer)) { diff --git a/src/g_demo.c b/src/g_demo.c index 388142013..141916b44 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -45,7 +45,7 @@ // SRB2Kart #include "d_netfil.h" // nameonly -#include "lua_script.h" // LUA_ArchiveDemo and LUA_UnArchiveDemo +#include "lua_script.h" // LUA_Sync #include "lua_libs.h" // gL (Lua state) #include "k_kart.h" @@ -2940,7 +2940,7 @@ void G_BeginRecording(void) // player lua vars, always saved even if empty if (demoflags & DF_LUAVARS) - LUA_Archive(&demobuf, false); + LUA_Sync(&demobuf, false, false); memset(&oldcmd,0,sizeof(oldcmd)); memset(&oldghost,0,sizeof(oldghost)); @@ -3793,7 +3793,7 @@ void G_DoPlayDemo(char *defdemoname) LUA_ClearState(); // No modeattacking check, DF_LUAVARS won't be present here. - LUA_UnArchive(&demobuf, false, G_CompatLevel(0x0002)); + LUA_Sync(&demobuf, false, G_CompatLevel(0x0002)); } splitscreen = 0; diff --git a/src/lua_script.c b/src/lua_script.c index 6d32162ac..ed719bcbb 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1846,8 +1846,9 @@ void LUA_Step(void) } } -void LUA_Archive(savebuffer_t *save, boolean network) +void LUA_Sync(savebuffer_t *save, boolean network, boolean compat) { + UINT32 mobjnum; INT32 i; thinker_t *th; @@ -1858,71 +1859,60 @@ void LUA_Archive(savebuffer_t *save, boolean network) { if (!playeringame[i] && i > 0) // NEVER skip player 0, this is for dedi servs. continue; + // all players in game will be archived, even if they just add a 0. - ArchiveExtVars(&save->p, &players[i], "player"); + if (save->write) + ArchiveExtVars(&save->p, &players[i], "player"); + else + UnArchiveExtVars(&save->p, &players[i], compat); } - if (network == true) + if (save->write) { - if (gamestate == GS_LEVEL) + if (network == true) { - for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + if (gamestate == GS_LEVEL) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; - // archive function will determine when to skip mobjs, - // and write mobjnum in otherwise. - ArchiveExtVars(&save->p, th, "mobj"); + // archive function will determine when to skip mobjs, + // and write mobjnum in otherwise. + ArchiveExtVars(&save->p, th, "mobj"); + } } + + WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. + + LUA_HookNetArchive(NetArchive, save); // call the NetArchive hook in archive mode } - - WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. - LUA_HookNetArchive(NetArchive, save); // call the NetArchive hook in archive mode + ArchiveTables(&save->p); } - - ArchiveTables(&save->p); - - if (gL) - lua_pop(gL, 1); // pop tables -} - -void LUA_UnArchive(savebuffer_t *save, boolean network, boolean compat) -{ - UINT32 mobjnum; - INT32 i; - thinker_t *th; - - if (gL) - lua_newtable(gL); // tables to be read - - for (i = 0; i < MAXPLAYERS; i++) + else { - if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. - continue; - UnArchiveExtVars(&save->p, &players[i], compat); + if (network == true) + { + do { + mobjnum = READUINT32(save->p); // read a mobjnum + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj + continue; + UnArchiveExtVars(&save->p, th, false); // apply variables + } + } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. + + LUA_HookNetArchive(NetUnArchive, save); // call the NetArchive hook in unarchive mode + } + + UnArchiveTables(&save->p, compat); } - if (network == true) - { - do { - mobjnum = READUINT32(save->p); // read a mobjnum - for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) - { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj - continue; - UnArchiveExtVars(&save->p, th, false); // apply variables - } - } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. - - LUA_HookNetArchive(NetUnArchive, save); // call the NetArchive hook in unarchive mode - } - - UnArchiveTables(&save->p, compat); - if (gL) lua_pop(gL, 1); // pop tables } diff --git a/src/lua_script.h b/src/lua_script.h index 084333f8d..41b9ee590 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -61,8 +61,7 @@ void LUA_DumpFile(const char *filename); #endif fixed_t LUA_EvalMath(const char *word); void LUA_Step(void); -void LUA_Archive(savebuffer_t *save, boolean network); -void LUA_UnArchive(savebuffer_t *save, boolean network, boolean compat); +void LUA_Sync(savebuffer_t *save, boolean network, boolean compat); void LUA_SetCFunctionField(lua_State *L, const char *name, lua_CFunction value); diff --git a/src/p_saveg.c b/src/p_saveg.c index cfe2e3d17..edd0ce146 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4476,7 +4476,7 @@ void P_SaveNetGame(savebuffer_t *save, boolean resending) } ACS_Archive(save); - LUA_Archive(save, true); + LUA_Sync(save, true, false); P_ArchiveLuabanksAndConsistency(save); @@ -4529,7 +4529,7 @@ boolean P_LoadNetGame(savebuffer_t *save, boolean reloading) } ACS_UnArchive(save); - LUA_UnArchive(save, true, false); + LUA_Sync(save, true, false); // This is stupid and hacky, but maybe it'll work! P_SetRandSeed(P_GetInitSeed());