From bda0ffe94b4491628df2626d4831c98a475a6e1f Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Fri, 30 Apr 2021 18:20:55 -0500 Subject: [PATCH 1/2] You've been blocked --- src/lua_hook.h | 2 +- src/lua_hooklib.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++ src/p_mobj.c | 2 +- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 0d631aa4e..8d80ec8c6 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -106,7 +106,7 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 #define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer #define LUAh_ShieldSpawn(player) LUAh_PlayerHook(player, hook_ShieldSpawn) // Hook for P_SpawnShieldOrb #define LUAh_ShieldSpecial(player) LUAh_PlayerHook(player, hook_ShieldSpecial) // Hook for shield abilities -#define LUAh_MobjMoveBlocked(mo) LUAh_MobjHook(mo, hook_MobjMoveBlocked) // Hook for P_XYMovement (when movement is blocked) +boolean LUAh_MobjMoveBlocked(mobj_t *mo, mobj_t *thing, line_t *line); // Hook for P_XYMovement (when movement is blocked) boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing); // Hook for P_SpawnMapThing by mobj type boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj); // Hook for P_PlayerAfterThink Smiles mobj-following UINT8 LUAh_PlayerCanDamage(player_t *player, mobj_t *mobj); // Hook for P_PlayerCanDamage diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 1665e36b0..2b4eda525 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -1414,6 +1414,80 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) // stack: tables } +boolean LUAh_MobjMoveBlocked(mobj_t *mo, mobj_t *thing, line_t *line) +{ + hook_p hookp; + boolean hooked = false; + if (!gL || !(hooksAvailable[hook_MobjMoveBlocked/8] & (1<<(hook_MobjMoveBlocked%8)))) + return false; + + if (!(mobjhooks[MT_NULL] || mobjhooks[mo->type])) + return false; + + lua_settop(gL, 0); + lua_pushcfunction(gL, LUA_GetErrorMessage); + + // Look for all generic mobj move blocked hooks + for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) + { + if (hookp->type != hook_MobjMoveBlocked) + continue; + + ps_lua_mobjhooks++; + if (lua_gettop(gL) == 1) + { + LUA_PushUserdata(gL, mo, META_MOBJ); + LUA_PushUserdata(gL, thing, META_MOBJ); + LUA_PushUserdata(gL, line, META_LINE); + } + PushHook(gL, hookp); + lua_pushvalue(gL, -4); + lua_pushvalue(gL, -4); + lua_pushvalue(gL, -4); + if (lua_pcall(gL, 3, 1, 1)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + continue; + } + if (lua_toboolean(gL, -1)) + hooked = true; + lua_pop(gL, 1); + } + + for (hookp = mobjhooks[mo->type]; hookp; hookp = hookp->next) + { + if (hookp->type != hook_MobjMoveBlocked) + continue; + + ps_lua_mobjhooks++; + if (lua_gettop(gL) == 1) + { + LUA_PushUserdata(gL, mo, META_MOBJ); + LUA_PushUserdata(gL, thing, META_MOBJ); + LUA_PushUserdata(gL, line, META_LINE); + } + PushHook(gL, hookp); + lua_pushvalue(gL, -4); + lua_pushvalue(gL, -4); + lua_pushvalue(gL, -4); + if (lua_pcall(gL, 3, 1, 1)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + continue; + } + if (lua_toboolean(gL, -1)) + hooked = true; + lua_pop(gL, 1); + } + + lua_settop(gL, 0); + return hooked; +} + boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing) { hook_p hookp; diff --git a/src/p_mobj.c b/src/p_mobj.c index 49db6daee..bac3cd2df 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1844,7 +1844,7 @@ void P_XYMovement(mobj_t *mo) B_MoveBlocked(player); } - if (LUAh_MobjMoveBlocked(mo)) + if (LUAh_MobjMoveBlocked(mo, tmhitthing, blockingline)) { if (P_MobjWasRemoved(mo)) return; From cb619fad5d762ba8d8dd20e9a979a04ced7c943f Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Wed, 7 Jul 2021 19:57:28 -0500 Subject: [PATCH 2/2] Rebase on !1307 --- src/lua_hook.h | 1 + src/lua_hooklib.c | 13 +++++++++++++ src/p_mobj.c | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 223b83c61..1af28aac5 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -115,6 +115,7 @@ int LUA_HookTouchSpecial(mobj_t *special, mobj_t *toucher); int LUA_HookShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype); int LUA_HookMobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype); int LUA_HookMobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype); +int LUA_HookMobjMoveBlocked(mobj_t *, mobj_t *, line_t *); int LUA_HookBotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd); void LUA_HookLinedefExecute(line_t *, mobj_t *, sector_t *); int LUA_HookPlayerMsg(int source, int target, int flags, char *msg); diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index d1b0d3bdd..f2e9b5233 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -713,6 +713,19 @@ int LUA_HookMobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 d MOBJ_HOOK(MobjDeath), 4, res_true); } +int LUA_HookMobjMoveBlocked(mobj_t *t1, mobj_t *t2, line_t *line) +{ + Hook_State hook; + if (prepare_mobj_hook(&hook, 0, MOBJ_HOOK(MobjMoveBlocked), t1->type)) + { + LUA_PushUserdata(gL, t1, META_MOBJ); + LUA_PushUserdata(gL, t2, META_MOBJ); + LUA_PushUserdata(gL, line, META_LINE); + call_hooks(&hook, 3, 1, res_true); + } + return hook.status; +} + typedef struct { mobj_t * tails; ticcmd_t * cmd; diff --git a/src/p_mobj.c b/src/p_mobj.c index 10220fff6..f2fae6cc6 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1844,7 +1844,7 @@ void P_XYMovement(mobj_t *mo) B_MoveBlocked(player); } - if (LUA_HookMobj(mo, MOBJ_HOOK(MobjMoveBlocked))) + if (LUA_HookMobjMoveBlocked(mo, tmhitthing, blockingline)) { if (P_MobjWasRemoved(mo)) return;