some stuff i forgor

This commit is contained in:
Alug committed 2024-09-16 17:33:31 +02:00
1 parent 0d999d7a70
commit 3f1c8db362
2 files changed
+46 -39

No files matched your search

+42 -35
View File
@@ -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
+4 -4
View File
@@ -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);