Merge branch 'fix-hurtmsg-hook' into 'next'

Fix HurtMsg inflictor mobj type discriminator

Closes #874

See merge request STJr/SRB2!1903
This commit is contained in:
MascaraSnake 2023-01-07 10:32:58 +00:00
commit 6ece0f1a00
2 changed files with 18 additions and 13 deletions

View file

@ -41,6 +41,7 @@ automatically.
X (MobjMoveBlocked),/* P_XYMovement (when movement is blocked) */\
X (MapThingSpawn),/* P_SpawnMapThing */\
X (FollowMobj),/* P_PlayerAfterThink Smiles mobj-following */\
X (HurtMsg),/* imhurttin */\
#define HOOK_LIST(X) \
X (NetVars),/* add to archive table (netsave) */\
@ -56,7 +57,6 @@ automatically.
X (JumpSpinSpecial),/* P_DoJumpStuff (Spin button effect (mid-air)) */\
X (BotTiccmd),/* B_BuildTiccmd */\
X (PlayerMsg),/* chat messages */\
X (HurtMsg),/* imhurttin */\
X (PlayerSpawn),/* G_SpawnPlayer */\
X (ShieldSpawn),/* P_SpawnShieldOrb */\
X (ShieldSpecial),/* shield abilities */\

View file

@ -73,7 +73,7 @@ static boolean mobj_hook_available(int hook_type, mobjtype_t mobj_type)
return
(
mobjHookIds [MT_NULL] [hook_type].numHooks > 0 ||
mobjHookIds[mobj_type][hook_type].numHooks > 0
(mobj_type < NUMMOBJTYPES && mobjHookIds[mobj_type][hook_type].numHooks > 0)
);
}
@ -344,8 +344,11 @@ static boolean prepare_mobj_hook
Hook_State * hook,
int default_status,
int hook_type,
mobjtype_t mobj_type
mobj_t * primary_mobj
){
const mobjtype_t mobj_type =
primary_mobj ? primary_mobj->type : NUMMOBJTYPES;
#ifdef PARANOIA
if (mobj_type == MT_NULL)
I_Error("MT_NULL has been passed to a mobj hook\n");
@ -506,7 +509,9 @@ static int call_hooks
{
/* call generic mobj hooks first */
calls += call_mobj_type_hooks(hook, MT_NULL);
calls += call_mobj_type_hooks(hook, hook->mobj_type);
if (hook->mobj_type < NUMMOBJTYPES)
calls += call_mobj_type_hooks(hook, hook->mobj_type);
ps_lua_mobjhooks.value.i += calls;
}
@ -554,7 +559,7 @@ static void res_force(Hook_State *hook)
int LUA_HookMobj(mobj_t *mobj, int hook_type)
{
Hook_State hook;
if (prepare_mobj_hook(&hook, false, hook_type, mobj->type))
if (prepare_mobj_hook(&hook, false, hook_type, mobj))
{
LUA_PushUserdata(gL, mobj, META_MOBJ);
call_hooks(&hook, 1, res_true);
@ -565,7 +570,7 @@ int LUA_HookMobj(mobj_t *mobj, int hook_type)
int LUA_Hook2Mobj(mobj_t *t1, mobj_t *t2, int hook_type)
{
Hook_State hook;
if (prepare_mobj_hook(&hook, 0, hook_type, t1->type))
if (prepare_mobj_hook(&hook, 0, hook_type, t1))
{
LUA_PushUserdata(gL, t1, META_MOBJ);
LUA_PushUserdata(gL, t2, META_MOBJ);
@ -735,7 +740,7 @@ void LUA_HookThinkFrame(void)
int LUA_HookMobjLineCollide(mobj_t *mobj, line_t *line)
{
Hook_State hook;
if (prepare_mobj_hook(&hook, 0, MOBJ_HOOK(MobjLineCollide), mobj->type))
if (prepare_mobj_hook(&hook, 0, MOBJ_HOOK(MobjLineCollide), mobj))
{
LUA_PushUserdata(gL, mobj, META_MOBJ);
LUA_PushUserdata(gL, line, META_LINE);
@ -747,7 +752,7 @@ int LUA_HookMobjLineCollide(mobj_t *mobj, line_t *line)
int LUA_HookTouchSpecial(mobj_t *special, mobj_t *toucher)
{
Hook_State hook;
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(TouchSpecial), special->type))
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(TouchSpecial), special))
{
LUA_PushUserdata(gL, special, META_MOBJ);
LUA_PushUserdata(gL, toucher, META_MOBJ);
@ -767,7 +772,7 @@ static int damage_hook
Hook_Callback results_handler
){
Hook_State hook;
if (prepare_mobj_hook(&hook, 0, hook_type, target->type))
if (prepare_mobj_hook(&hook, 0, hook_type, target))
{
LUA_PushUserdata(gL, target, META_MOBJ);
LUA_PushUserdata(gL, inflictor, META_MOBJ);
@ -801,7 +806,7 @@ int LUA_HookMobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 d
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))
if (prepare_mobj_hook(&hook, 0, MOBJ_HOOK(MobjMoveBlocked), t1))
{
LUA_PushUserdata(gL, t1, META_MOBJ);
LUA_PushUserdata(gL, t2, META_MOBJ);
@ -928,7 +933,7 @@ int LUA_HookPlayerMsg(int source, int target, int flags, char *msg)
int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 damagetype)
{
Hook_State hook;
if (prepare_hook(&hook, false, HOOK(HurtMsg)))
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(HurtMsg), inflictor))
{
LUA_PushUserdata(gL, player, META_PLAYER);
LUA_PushUserdata(gL, inflictor, META_MOBJ);
@ -972,7 +977,7 @@ void LUA_HookNetArchive(lua_CFunction archFunc)
int LUA_HookMapThingSpawn(mobj_t *mobj, mapthing_t *mthing)
{
Hook_State hook;
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(MapThingSpawn), mobj->type))
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(MapThingSpawn), mobj))
{
LUA_PushUserdata(gL, mobj, META_MOBJ);
LUA_PushUserdata(gL, mthing, META_MAPTHING);
@ -984,7 +989,7 @@ int LUA_HookMapThingSpawn(mobj_t *mobj, mapthing_t *mthing)
int LUA_HookFollowMobj(player_t *player, mobj_t *mobj)
{
Hook_State hook;
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(FollowMobj), mobj->type))
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(FollowMobj), mobj))
{
LUA_PushUserdata(gL, player, META_PLAYER);
LUA_PushUserdata(gL, mobj, META_MOBJ);