fix lugstuff crash

This commit is contained in:
Alug committed 2024-11-21 20:00:52 +01:00
1 parent 6b7fe5ac25
commit 3a236ca2ad
3 files changed
+40 -7

No files matched your search

+34 -1
View File
@@ -873,6 +873,7 @@ int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source)
return hook.status;
}
#if 0
void LUA_HookNetArchive(lua_CFunction archFunc)
{
const hook_t * map = &hookIds[HOOK(NetVars)];
@@ -891,7 +892,7 @@ void LUA_HookNetArchive(lua_CFunction archFunc)
// tables becomes an upvalue of archFunc
lua_pushvalue(gL, -1);
lua_pushcclosure(gL, archFunc, 1);
lua_pushcclosure(gL, archFunc, 2);
// stack: tables, archFunc
init_hook_call(&hook, 0, res_none);
@@ -902,6 +903,38 @@ void LUA_HookNetArchive(lua_CFunction archFunc)
// stack: tables
}
}
#endif
void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save) //
{
const hook_t * map = &hookIds[HOOK(NetVars)];
Hook_State hook;
/* this is a remarkable case where the stack isn't reset */
if (map->numHooks > 0)
{
// stack: tables
I_Assert(lua_gettop(gL) > 0);
I_Assert(lua_istable(gL, -1));
push_error_handler();
lua_insert(gL, EINDEX);
begin_hook_values(&hook);
// tables becomes an upvalue of archFunc
lua_pushvalue(gL, -1);
lua_pushlightuserdata(gL, save);
lua_pushcclosure(gL, archFunc, 2);
// stack: tables, savebuffer_t, archFunc
init_hook_call(&hook, 0, res_none);
call_mapped(&hook, map);
lua_pop(gL, 1); // pop archFunc
lua_remove(gL, EINDEX); // pop error handler
// stack: tables
}
}
void LUA_HookPlayerQuit(player_t *plr, int reason)
{
+4 -4
View File
@@ -1397,8 +1397,8 @@ void LUA_Archive(savebuffer_t *save, boolean network)
}
WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum.
//LUA_HookNetArchive(NetArchive, save); // call the NetArchive hook in archive mode
LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode
LUA_HookNetArchive(NetArchive, save); // call the NetArchive hook in archive mode
//LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode
}
ArchiveTables(&save->p);
@@ -1438,8 +1438,8 @@ void LUA_UnArchive(savebuffer_t *save, boolean network)
}
} while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker.
//LUA_HookNetArchive(NetUnArchive, save); // call the NetArchive hook in unarchive mode
LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode
LUA_HookNetArchive(NetUnArchive, save); // call the NetArchive hook in unarchive mode
//LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode
}
UnArchiveTables(&save->p, network);
+2 -2
View File
@@ -74,8 +74,8 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c
void LUA_CVarChanged(const char *name); // lua_consolelib.c
int Lua_optoption(lua_State *L, int narg, int def, int list_ref);
int Lua_CreateFieldTable(lua_State *L, const char *const lst[]);
//void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save);
void LUA_HookNetArchive(lua_CFunction archFunc);
void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save);
//void LUA_HookNetArchive(lua_CFunction archFunc);
// Console wrapper
void COM_Lua_f(void);