2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-05-18 00:42:11 +00:00
|
|
|
// Copyright (C) 2012-2016 by John "JTE" Muniz.
|
2019-12-06 18:49:42 +00:00
|
|
|
// Copyright (C) 2012-2019 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file lua_hooklib.c
|
|
|
|
/// \brief hooks for Lua scripting
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#ifdef HAVE_BLUA
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "p_mobj.h"
|
2014-06-18 20:28:09 +00:00
|
|
|
#include "g_game.h"
|
2014-03-15 16:59:03 +00:00
|
|
|
#include "r_things.h"
|
|
|
|
#include "b_bot.h"
|
|
|
|
#include "z_zone.h"
|
|
|
|
|
|
|
|
#include "lua_script.h"
|
|
|
|
#include "lua_libs.h"
|
|
|
|
#include "lua_hook.h"
|
|
|
|
#include "lua_hud.h" // hud_running errors
|
|
|
|
|
2014-04-14 05:14:58 +00:00
|
|
|
static UINT8 hooksAvailable[(hook_MAX/8)+1];
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
const char *const hookNames[hook_MAX+1] = {
|
|
|
|
"NetVars",
|
|
|
|
"MapChange",
|
|
|
|
"MapLoad",
|
|
|
|
"PlayerJoin",
|
|
|
|
"ThinkFrame",
|
|
|
|
"MobjSpawn",
|
|
|
|
"MobjCollide",
|
|
|
|
"MobjMoveCollide",
|
|
|
|
"TouchSpecial",
|
|
|
|
"MobjFuse",
|
|
|
|
"MobjThinker",
|
|
|
|
"BossThinker",
|
|
|
|
"ShouldDamage",
|
|
|
|
"MobjDamage",
|
|
|
|
"MobjDeath",
|
|
|
|
"BossDeath",
|
|
|
|
"MobjRemoved",
|
2014-08-04 03:49:33 +00:00
|
|
|
"JumpSpecial",
|
|
|
|
"AbilitySpecial",
|
|
|
|
"SpinSpecial",
|
|
|
|
"JumpSpinSpecial",
|
2014-03-15 16:59:03 +00:00
|
|
|
"BotTiccmd",
|
|
|
|
"BotAI",
|
|
|
|
"LinedefExecute",
|
2014-06-18 20:28:09 +00:00
|
|
|
"PlayerMsg",
|
2014-08-04 03:49:33 +00:00
|
|
|
"HurtMsg",
|
2016-02-14 11:19:40 +00:00
|
|
|
"PlayerSpawn",
|
2016-10-20 19:55:15 +00:00
|
|
|
"ShieldSpawn",
|
2016-10-24 12:52:36 +00:00
|
|
|
"ShieldSpecial",
|
2017-01-21 23:49:18 +00:00
|
|
|
"MobjMoveBlocked",
|
2017-04-15 20:41:22 +00:00
|
|
|
"MapThingSpawn",
|
2017-10-02 13:08:58 +00:00
|
|
|
"FollowMobj",
|
"PlayerCanDamage" hook!
* Takes function(player, mo) input.
* Return TRUE for stating that yes, the player is in a state that can cause contact damage, do with that what you will.
* Return FALSE for stating that no, the player is weak and vulnerable and cannot cause contact damage, do with that what you will.
* Return NIL for allowing the function to continue regular operation.
Fills a different ideological niche than ShouldDamage - that's for determining whether damage dished between two objects should happen, this is for determining which way around damage should be dished when considering a player-object interaction.
Or, in other words, think of it as "ShouldDamage is whether damage that has been requested should be granted, for object-object interaction, while PlayerCanDamage is for whether global player properties should cause damage to enemies and monitors in the first place, like spinning, hammering or stomping."
2019-06-19 11:55:05 +00:00
|
|
|
"PlayerCanDamage",
|
2016-10-21 02:25:11 +00:00
|
|
|
"PlayerQuit",
|
2019-10-14 00:50:46 +00:00
|
|
|
"IntermissionThinker",
|
2014-03-15 16:59:03 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
// Hook metadata
|
|
|
|
struct hook_s
|
|
|
|
{
|
|
|
|
struct hook_s *next;
|
|
|
|
enum hook type;
|
|
|
|
UINT16 id;
|
|
|
|
union {
|
|
|
|
mobjtype_t mt;
|
|
|
|
char *skinname;
|
|
|
|
char *funcname;
|
|
|
|
} s;
|
|
|
|
boolean error;
|
|
|
|
};
|
|
|
|
typedef struct hook_s* hook_p;
|
|
|
|
|
2015-06-10 15:06:56 +00:00
|
|
|
#define FMT_HOOKID "hook_%d"
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2016-11-04 17:56:25 +00:00
|
|
|
// For each mobj type, a linked list to its thinker and collision hooks.
|
|
|
|
// That way, we don't have to iterate through all the hooks.
|
|
|
|
// We could do that with all other mobj hooks, but it would probably just be
|
|
|
|
// a waste of memory since they are only called occasionally. Probably...
|
|
|
|
static hook_p mobjthinkerhooks[NUMMOBJTYPES];
|
|
|
|
static hook_p mobjcollidehooks[NUMMOBJTYPES];
|
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// For each mobj type, a linked list for other mobj hooks
|
|
|
|
static hook_p mobjhooks[NUMMOBJTYPES];
|
|
|
|
|
|
|
|
// A linked list for player hooks
|
|
|
|
static hook_p playerhooks;
|
|
|
|
|
|
|
|
// A linked list for linedef executor hooks
|
|
|
|
static hook_p linedefexecutorhooks;
|
|
|
|
|
2016-11-04 17:56:25 +00:00
|
|
|
// For other hooks, a unique linked list
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p roothook;
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// Takes hook, function, and additional arguments (mobj type to act on, etc.)
|
|
|
|
static int lib_addHook(lua_State *L)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
static struct hook_s hook = {NULL, 0, 0, {0}, false};
|
2016-11-04 17:56:25 +00:00
|
|
|
static UINT32 nextid;
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp, *lastp;
|
|
|
|
|
|
|
|
hook.type = luaL_checkoption(L, 1, NULL, hookNames);
|
|
|
|
lua_remove(L, 1);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
luaL_checktype(L, 1, LUA_TFUNCTION);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2017-04-25 20:45:53 +00:00
|
|
|
if (!lua_lumploading)
|
|
|
|
return luaL_error(L, "This function cannot be called from within a hook or coroutine!");
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
switch(hook.type)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
// Take a mobjtype enum which this hook is specifically for.
|
|
|
|
case hook_MobjSpawn:
|
|
|
|
case hook_MobjCollide:
|
|
|
|
case hook_MobjMoveCollide:
|
|
|
|
case hook_TouchSpecial:
|
|
|
|
case hook_MobjFuse:
|
|
|
|
case hook_MobjThinker:
|
|
|
|
case hook_BossThinker:
|
|
|
|
case hook_ShouldDamage:
|
|
|
|
case hook_MobjDamage:
|
|
|
|
case hook_MobjDeath:
|
|
|
|
case hook_BossDeath:
|
|
|
|
case hook_MobjRemoved:
|
2015-06-10 11:28:09 +00:00
|
|
|
case hook_HurtMsg:
|
2017-01-21 23:49:18 +00:00
|
|
|
case hook_MobjMoveBlocked:
|
2017-04-15 20:41:22 +00:00
|
|
|
case hook_MapThingSpawn:
|
2015-06-10 11:28:09 +00:00
|
|
|
hook.s.mt = MT_NULL;
|
|
|
|
if (lua_isnumber(L, 2))
|
|
|
|
hook.s.mt = lua_tonumber(L, 2);
|
2016-11-04 17:56:25 +00:00
|
|
|
luaL_argcheck(L, hook.s.mt < NUMMOBJTYPES, 2, "invalid mobjtype_t");
|
2014-03-15 16:59:03 +00:00
|
|
|
break;
|
2015-06-10 11:28:09 +00:00
|
|
|
case hook_BotAI:
|
|
|
|
hook.s.skinname = NULL;
|
|
|
|
if (lua_isstring(L, 2))
|
2014-03-15 16:59:03 +00:00
|
|
|
{ // lowercase copy
|
2015-06-10 11:28:09 +00:00
|
|
|
const char *s = lua_tostring(L, 2);
|
|
|
|
char *p = hook.s.skinname = ZZ_Alloc(strlen(s)+1);
|
2014-03-15 16:59:03 +00:00
|
|
|
do {
|
|
|
|
*p = tolower(*s);
|
|
|
|
++p;
|
|
|
|
} while(*(++s));
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
break;
|
2015-06-10 11:28:09 +00:00
|
|
|
case hook_LinedefExecute: // Linedef executor functions
|
2014-03-15 16:59:03 +00:00
|
|
|
{ // uppercase copy
|
2015-06-10 11:28:09 +00:00
|
|
|
const char *s = luaL_checkstring(L, 2);
|
|
|
|
char *p = hook.s.funcname = ZZ_Alloc(strlen(s)+1);
|
2014-03-15 16:59:03 +00:00
|
|
|
do {
|
|
|
|
*p = toupper(*s);
|
|
|
|
++p;
|
|
|
|
} while(*(++s));
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
lua_settop(L, 1); // lua stack contains only the function now.
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
hooksAvailable[hook.type/8] |= 1<<(hook.type%8);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
// set hook.id to the highest id + 1
|
2016-11-04 17:56:25 +00:00
|
|
|
hook.id = nextid++;
|
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// Special cases for some hook types (see the comments above mobjthinkerhooks declaration)
|
|
|
|
switch(hook.type)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2016-12-15 20:05:54 +00:00
|
|
|
case hook_MobjThinker:
|
2016-11-04 17:56:25 +00:00
|
|
|
lastp = &mobjthinkerhooks[hook.s.mt];
|
2016-12-15 20:05:54 +00:00
|
|
|
break;
|
|
|
|
case hook_MobjCollide:
|
|
|
|
case hook_MobjMoveCollide:
|
2016-11-04 17:56:25 +00:00
|
|
|
lastp = &mobjcollidehooks[hook.s.mt];
|
2016-12-15 20:05:54 +00:00
|
|
|
break;
|
|
|
|
case hook_MobjSpawn:
|
|
|
|
case hook_TouchSpecial:
|
|
|
|
case hook_MobjFuse:
|
|
|
|
case hook_BossThinker:
|
|
|
|
case hook_ShouldDamage:
|
|
|
|
case hook_MobjDamage:
|
|
|
|
case hook_MobjDeath:
|
|
|
|
case hook_BossDeath:
|
|
|
|
case hook_MobjRemoved:
|
2017-01-21 23:49:18 +00:00
|
|
|
case hook_MobjMoveBlocked:
|
2017-04-15 20:41:22 +00:00
|
|
|
case hook_MapThingSpawn:
|
2016-12-15 20:05:54 +00:00
|
|
|
lastp = &mobjhooks[hook.s.mt];
|
|
|
|
break;
|
|
|
|
case hook_JumpSpecial:
|
|
|
|
case hook_AbilitySpecial:
|
|
|
|
case hook_SpinSpecial:
|
|
|
|
case hook_JumpSpinSpecial:
|
|
|
|
case hook_PlayerSpawn:
|
2017-10-02 13:08:58 +00:00
|
|
|
case hook_FollowMobj:
|
"PlayerCanDamage" hook!
* Takes function(player, mo) input.
* Return TRUE for stating that yes, the player is in a state that can cause contact damage, do with that what you will.
* Return FALSE for stating that no, the player is weak and vulnerable and cannot cause contact damage, do with that what you will.
* Return NIL for allowing the function to continue regular operation.
Fills a different ideological niche than ShouldDamage - that's for determining whether damage dished between two objects should happen, this is for determining which way around damage should be dished when considering a player-object interaction.
Or, in other words, think of it as "ShouldDamage is whether damage that has been requested should be granted, for object-object interaction, while PlayerCanDamage is for whether global player properties should cause damage to enemies and monitors in the first place, like spinning, hammering or stomping."
2019-06-19 11:55:05 +00:00
|
|
|
case hook_PlayerCanDamage:
|
2018-12-24 16:31:00 +00:00
|
|
|
case hook_ShieldSpawn:
|
|
|
|
case hook_ShieldSpecial:
|
2016-12-15 20:05:54 +00:00
|
|
|
lastp = &playerhooks;
|
|
|
|
break;
|
|
|
|
case hook_LinedefExecute:
|
|
|
|
lastp = &linedefexecutorhooks;
|
|
|
|
break;
|
|
|
|
default:
|
2016-11-04 17:56:25 +00:00
|
|
|
lastp = &roothook;
|
2016-12-15 20:05:54 +00:00
|
|
|
break;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 17:56:25 +00:00
|
|
|
// iterate the hook metadata structs
|
2015-06-10 11:28:09 +00:00
|
|
|
// set lastp to the last hook struct's "next" pointer.
|
2016-11-04 17:56:25 +00:00
|
|
|
for (hookp = *lastp; hookp; hookp = hookp->next)
|
2015-06-10 11:28:09 +00:00
|
|
|
lastp = &hookp->next;
|
|
|
|
// allocate a permanent memory struct to stuff hook.
|
|
|
|
hookp = ZZ_Alloc(sizeof(struct hook_s));
|
|
|
|
memcpy(hookp, &hook, sizeof(struct hook_s));
|
|
|
|
// tack it onto the end of the linked list.
|
|
|
|
*lastp = hookp;
|
|
|
|
|
|
|
|
// set the hook function in the registry.
|
|
|
|
lua_pushfstring(L, FMT_HOOKID, hook.id);
|
|
|
|
lua_pushvalue(L, 1);
|
|
|
|
lua_settable(L, LUA_REGISTRYINDEX);
|
2014-03-15 16:59:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LUA_HookLib(lua_State *L)
|
|
|
|
{
|
2014-04-14 05:14:58 +00:00
|
|
|
memset(hooksAvailable,0,sizeof(UINT8[(hook_MAX/8)+1]));
|
2015-06-10 11:28:09 +00:00
|
|
|
roothook = NULL;
|
2014-03-15 16:59:03 +00:00
|
|
|
lua_register(L, "addHook", lib_addHook);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean LUAh_MobjHook(mobj_t *mo, enum hook which)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-03-15 16:59:03 +00:00
|
|
|
boolean hooked = false;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return false;
|
|
|
|
|
2017-12-17 20:59:24 +00:00
|
|
|
I_Assert(mo->type < NUMMOBJTYPES);
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// Look for all generic mobj hooks
|
|
|
|
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != which)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
|
|
|
LUA_PushUserdata(gL, mo, META_MOBJ);
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2);
|
|
|
|
if (lua_pcall(gL, 1, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-03-15 16:59:03 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
for (hookp = mobjhooks[mo->type]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != which)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
|
|
|
LUA_PushUserdata(gL, mo, META_MOBJ);
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2);
|
|
|
|
if (lua_pcall(gL, 1, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-03-15 16:59:03 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
return hooked;
|
|
|
|
}
|
|
|
|
|
2014-08-04 03:49:33 +00:00
|
|
|
boolean LUAh_PlayerHook(player_t *plr, enum hook which)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-08-04 03:49:33 +00:00
|
|
|
boolean hooked = false;
|
|
|
|
if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
|
|
|
|
return false;
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-08-04 03:49:33 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
for (hookp = playerhooks; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != which)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
|
|
|
LUA_PushUserdata(gL, plr, META_PLAYER);
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2);
|
|
|
|
if (lua_pcall(gL, 1, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-08-04 03:49:33 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-08-04 03:49:33 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2014-08-04 03:49:33 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-08-04 03:49:33 +00:00
|
|
|
return hooked;
|
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// Hook for map change (before load)
|
2018-11-30 17:01:40 +00:00
|
|
|
void LUAh_MapChange(INT16 mapnumber)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_MapChange/8] & (1<<(hook_MapChange%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2018-11-30 17:01:40 +00:00
|
|
|
lua_pushinteger(gL, mapnumber);
|
2015-06-10 11:28:09 +00:00
|
|
|
|
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_MapChange)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2);
|
|
|
|
LUA_Call(gL, 1);
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for map load
|
|
|
|
void LUAh_MapLoad(void)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_MapLoad/8] & (1<<(hook_MapLoad%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
lua_pushinteger(gL, gamemap);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_MapLoad)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2);
|
|
|
|
LUA_Call(gL, 1);
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for Got_AddPlayer
|
|
|
|
void LUAh_PlayerJoin(int playernum)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_PlayerJoin/8] & (1<<(hook_PlayerJoin%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
lua_pushinteger(gL, playernum);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_PlayerJoin)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2);
|
|
|
|
LUA_Call(gL, 1);
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for frame (after mobj and player thinkers)
|
|
|
|
void LUAh_ThinkFrame(void)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_ThinkFrame/8] & (1<<(hook_ThinkFrame%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_ThinkFrame)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
if (lua_pcall(gL, 0, 0, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
hookp->error = true;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
// Hook for mobj collisions
|
|
|
|
UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-03-15 16:59:03 +00:00
|
|
|
UINT8 shouldCollide = 0; // 0 = default, 1 = force yes, 2 = force no.
|
2015-06-10 11:28:09 +00:00
|
|
|
if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-12-17 20:59:24 +00:00
|
|
|
I_Assert(thing1->type < NUMMOBJTYPES);
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// Look for all generic mobj collision hooks
|
|
|
|
for (hookp = mobjcollidehooks[MT_NULL]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != which)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2016-11-04 17:56:25 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, thing1, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, thing2, META_MOBJ);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2016-11-04 17:56:25 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2016-11-04 17:56:25 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (!lua_isnil(gL, -1))
|
|
|
|
{ // if nil, leave shouldCollide = 0.
|
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
shouldCollide = 1; // Force yes
|
|
|
|
else
|
|
|
|
shouldCollide = 2; // Force no
|
|
|
|
}
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2016-11-04 17:56:25 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
for (hookp = mobjcollidehooks[thing1->type]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != which)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, thing1, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, thing2, META_MOBJ);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-03-15 16:59:03 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (!lua_isnil(gL, -1))
|
|
|
|
{ // if nil, leave shouldCollide = 0.
|
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
shouldCollide = 1; // Force yes
|
|
|
|
else
|
|
|
|
shouldCollide = 2; // Force no
|
|
|
|
}
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
return shouldCollide;
|
|
|
|
}
|
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// Hook for mobj thinkers
|
|
|
|
boolean LUAh_MobjThinker(mobj_t *mo)
|
|
|
|
{
|
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
|
|
|
if (!gL || !(hooksAvailable[hook_MobjThinker/8] & (1<<(hook_MobjThinker%8))))
|
|
|
|
return false;
|
|
|
|
|
2017-12-17 20:59:24 +00:00
|
|
|
I_Assert(mo->type < NUMMOBJTYPES);
|
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
lua_settop(gL, 0);
|
|
|
|
|
|
|
|
// Look for all generic mobj thinker hooks
|
|
|
|
for (hookp = mobjthinkerhooks[MT_NULL]; hookp; hookp = hookp->next)
|
|
|
|
{
|
|
|
|
if (lua_gettop(gL) == 0)
|
|
|
|
LUA_PushUserdata(gL, mo, META_MOBJ);
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2);
|
|
|
|
if (lua_pcall(gL, 1, 1, 0)) {
|
|
|
|
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 = mobjthinkerhooks[mo->type]; hookp; hookp = hookp->next)
|
|
|
|
{
|
|
|
|
if (lua_gettop(gL) == 0)
|
|
|
|
LUA_PushUserdata(gL, mo, META_MOBJ);
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2);
|
|
|
|
if (lua_pcall(gL, 1, 1, 0)) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// Hook for P_TouchSpecialThing by mobj type
|
|
|
|
boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-03-15 16:59:03 +00:00
|
|
|
boolean hooked = false;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_TouchSpecial/8] & (1<<(hook_TouchSpecial%8))))
|
2015-06-10 11:28:09 +00:00
|
|
|
return 0;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2017-12-17 20:59:24 +00:00
|
|
|
I_Assert(special->type < NUMMOBJTYPES);
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// Look for all generic touch special hooks
|
|
|
|
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_TouchSpecial)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2016-12-15 20:05:54 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, special, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, toucher, META_MOBJ);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2016-12-15 20:05:54 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2016-12-15 20:05:54 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2016-12-15 20:05:54 +00:00
|
|
|
|
|
|
|
for (hookp = mobjhooks[special->type]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_TouchSpecial)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, special, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, toucher, META_MOBJ);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-04-14 05:14:58 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-04-14 05:14:58 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
return hooked;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for P_DamageMobj by mobj type (Should mobj take damage?)
|
2016-07-20 21:02:02 +00:00
|
|
|
UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-03-15 16:59:03 +00:00
|
|
|
UINT8 shouldDamage = 0; // 0 = default, 1 = force yes, 2 = force no.
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_ShouldDamage/8] & (1<<(hook_ShouldDamage%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-12-17 20:59:24 +00:00
|
|
|
I_Assert(target->type < NUMMOBJTYPES);
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// Look for all generic should damage hooks
|
|
|
|
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_ShouldDamage)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2016-12-15 20:05:54 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, target, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, inflictor, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, source, META_MOBJ);
|
|
|
|
lua_pushinteger(gL, damage);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
if (lua_pcall(gL, 4, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2016-12-15 20:05:54 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2016-12-15 20:05:54 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (!lua_isnil(gL, -1))
|
|
|
|
{
|
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
shouldDamage = 1; // Force yes
|
|
|
|
else
|
|
|
|
shouldDamage = 2; // Force no
|
|
|
|
}
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2016-12-15 20:05:54 +00:00
|
|
|
|
|
|
|
for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_ShouldDamage)
|
|
|
|
continue;
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, target, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, inflictor, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, source, META_MOBJ);
|
|
|
|
lua_pushinteger(gL, damage);
|
|
|
|
lua_pushinteger(gL, damagetype);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
if (lua_pcall(gL, 5, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-03-15 16:59:03 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (!lua_isnil(gL, -1))
|
|
|
|
{
|
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
shouldDamage = 1; // Force yes
|
|
|
|
else
|
|
|
|
shouldDamage = 2; // Force no
|
|
|
|
}
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
return shouldDamage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for P_DamageMobj by mobj type (Mobj actually takes damage!)
|
2016-07-20 21:02:02 +00:00
|
|
|
boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_MobjDamage/8] & (1<<(hook_MobjDamage%8))))
|
2015-06-10 11:28:09 +00:00
|
|
|
return 0;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2017-12-17 20:59:24 +00:00
|
|
|
I_Assert(target->type < NUMMOBJTYPES);
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// Look for all generic mobj damage hooks
|
|
|
|
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_MobjDamage)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2016-12-15 20:05:54 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, target, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, inflictor, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, source, META_MOBJ);
|
|
|
|
lua_pushinteger(gL, damage);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
if (lua_pcall(gL, 4, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2016-12-15 20:05:54 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2016-12-15 20:05:54 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2016-12-15 20:05:54 +00:00
|
|
|
|
|
|
|
for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_MobjDamage)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, target, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, inflictor, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, source, META_MOBJ);
|
|
|
|
lua_pushinteger(gL, damage);
|
|
|
|
lua_pushinteger(gL, damagetype);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
lua_pushvalue(gL, -6);
|
|
|
|
if (lua_pcall(gL, 5, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-03-15 16:59:03 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
return hooked;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for P_KillMobj by mobj type
|
2016-07-20 21:02:02 +00:00
|
|
|
boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_MobjDeath/8] & (1<<(hook_MobjDeath%8))))
|
2015-06-10 11:28:09 +00:00
|
|
|
return 0;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2017-12-17 20:59:24 +00:00
|
|
|
I_Assert(target->type < NUMMOBJTYPES);
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
// Look for all generic mobj death hooks
|
|
|
|
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_MobjDeath)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2016-12-15 20:05:54 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, target, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, inflictor, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, source, META_MOBJ);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -4);
|
|
|
|
lua_pushvalue(gL, -4);
|
|
|
|
lua_pushvalue(gL, -4);
|
|
|
|
if (lua_pcall(gL, 3, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2016-12-15 20:05:54 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2016-12-15 20:05:54 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2016-12-15 20:05:54 +00:00
|
|
|
|
|
|
|
for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_MobjDeath)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, target, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, inflictor, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, source, META_MOBJ);
|
|
|
|
lua_pushinteger(gL, damagetype);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
if (lua_pcall(gL, 4, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-03-15 16:59:03 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
return hooked;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for B_BuildTiccmd
|
|
|
|
boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
2014-03-15 16:59:03 +00:00
|
|
|
boolean hooked = false;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_BotTiccmd/8] & (1<<(hook_BotTiccmd%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_BotTiccmd)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, bot, META_PLAYER);
|
|
|
|
LUA_PushUserdata(gL, cmd, META_TICCMD);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-04-14 05:14:58 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-04-14 05:14:58 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
return hooked;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for B_BuildTailsTiccmd by skin name
|
|
|
|
boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
|
|
|
if (!gL || !(hooksAvailable[hook_BotAI/8] & (1<<(hook_BotAI%8))))
|
2014-03-15 16:59:03 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_BotAI
|
|
|
|
|| (hookp->s.skinname && strcmp(hookp->s.skinname, ((skin_t*)tails->skin)->name)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, sonic, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, tails, META_MOBJ);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 8, 0)) {
|
|
|
|
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;
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2019-06-19 11:28:57 +00:00
|
|
|
// This turns forward, backward, left, right, jump, and spin into a proper ticcmd for tails.
|
|
|
|
if (lua_istable(gL, 2+1)) {
|
|
|
|
boolean forward=false, backward=false, left=false, right=false, strafeleft=false, straferight=false, jump=false, spin=false;
|
2014-03-15 16:59:03 +00:00
|
|
|
#define CHECKFIELD(field) \
|
2019-06-19 11:28:57 +00:00
|
|
|
lua_getfield(gL, 2+1, #field);\
|
|
|
|
if (lua_toboolean(gL, -1))\
|
|
|
|
field = true;\
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
|
|
|
|
CHECKFIELD(forward)
|
|
|
|
CHECKFIELD(backward)
|
|
|
|
CHECKFIELD(left)
|
|
|
|
CHECKFIELD(right)
|
|
|
|
CHECKFIELD(strafeleft)
|
|
|
|
CHECKFIELD(straferight)
|
|
|
|
CHECKFIELD(jump)
|
|
|
|
CHECKFIELD(spin)
|
2014-03-15 16:59:03 +00:00
|
|
|
#undef CHECKFIELD
|
2019-06-19 11:28:57 +00:00
|
|
|
B_KeysToTiccmd(tails, cmd, forward, backward, left, right, strafeleft, straferight, jump, spin);
|
|
|
|
} else
|
|
|
|
B_KeysToTiccmd(tails, cmd, lua_toboolean(gL, 2+1), lua_toboolean(gL, 2+2), lua_toboolean(gL, 2+3), lua_toboolean(gL, 2+4), lua_toboolean(gL, 2+5), lua_toboolean(gL, 2+6), lua_toboolean(gL, 2+7), lua_toboolean(gL, 2+8));
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2019-06-19 11:28:57 +00:00
|
|
|
lua_pop(gL, 8);
|
|
|
|
hooked = true;
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
return hooked;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hook for linedef executors
|
2014-11-12 00:55:07 +00:00
|
|
|
boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
2014-04-14 05:14:58 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_LinedefExecute/8] & (1<<(hook_LinedefExecute%8))))
|
2015-06-10 11:28:09 +00:00
|
|
|
return 0;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2016-12-15 20:05:54 +00:00
|
|
|
for (hookp = linedefexecutorhooks; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (strcmp(hookp->s.funcname, line->text))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, line, META_LINE);
|
|
|
|
LUA_PushUserdata(gL, mo, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, sector, META_SECTOR);
|
2015-06-10 11:28:09 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -4);
|
|
|
|
lua_pushvalue(gL, -4);
|
|
|
|
lua_pushvalue(gL, -4);
|
|
|
|
LUA_Call(gL, 3);
|
|
|
|
hooked = true;
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
return hooked;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 15:44:58 +00:00
|
|
|
|
2014-06-18 20:28:09 +00:00
|
|
|
boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg)
|
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
2014-06-18 20:28:09 +00:00
|
|
|
if (!gL || !(hooksAvailable[hook_PlayerMsg/8] & (1<<(hook_PlayerMsg%8))))
|
|
|
|
return false;
|
2014-06-19 16:59:15 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-06-19 16:59:15 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_PlayerMsg)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, &players[source], META_PLAYER); // Source player
|
|
|
|
if (flags & 2 /*HU_CSAY*/) { // csay TODO: make HU_CSAY accessible outside hu_stuff.c
|
|
|
|
lua_pushinteger(gL, 3); // type
|
|
|
|
lua_pushnil(gL); // target
|
|
|
|
} else if (target == -1) { // sayteam
|
|
|
|
lua_pushinteger(gL, 1); // type
|
|
|
|
lua_pushnil(gL); // target
|
|
|
|
} else if (target == 0) { // say
|
|
|
|
lua_pushinteger(gL, 0); // type
|
|
|
|
lua_pushnil(gL); // target
|
|
|
|
} else { // sayto
|
|
|
|
lua_pushinteger(gL, 2); // type
|
|
|
|
LUA_PushUserdata(gL, &players[target-1], META_PLAYER); // target
|
2015-06-10 11:28:09 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
lua_pushstring(gL, msg); // msg
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
if (lua_pcall(gL, 4, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-06-18 20:28:09 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-06-18 20:28:09 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
return hooked;
|
2014-06-18 20:28:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:43:59 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
// Hook for hurt messages
|
2016-07-20 21:02:02 +00:00
|
|
|
boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 damagetype)
|
2014-08-04 03:49:33 +00:00
|
|
|
{
|
2015-06-10 11:28:09 +00:00
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
|
|
|
if (!gL || !(hooksAvailable[hook_HurtMsg/8] & (1<<(hook_HurtMsg%8))))
|
2014-08-04 03:49:33 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2014-08-04 03:49:33 +00:00
|
|
|
|
2015-06-10 11:28:09 +00:00
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_HurtMsg
|
|
|
|
|| (hookp->s.mt && !(inflictor && hookp->s.mt == inflictor->type)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2015-06-10 11:28:09 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, player, META_PLAYER);
|
|
|
|
LUA_PushUserdata(gL, inflictor, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, source, META_MOBJ);
|
|
|
|
lua_pushinteger(gL, damagetype);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
lua_pushvalue(gL, -5);
|
|
|
|
if (lua_pcall(gL, 4, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2014-08-04 03:49:33 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2014-08-04 03:49:33 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2015-06-10 11:28:09 +00:00
|
|
|
|
2015-06-10 12:06:16 +00:00
|
|
|
lua_settop(gL, 0);
|
2015-06-10 11:28:09 +00:00
|
|
|
return hooked;
|
2014-08-04 03:49:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-03 22:07:05 +00:00
|
|
|
void LUAh_NetArchiveHook(lua_CFunction archFunc)
|
|
|
|
{
|
|
|
|
hook_p hookp;
|
|
|
|
|
|
|
|
if (!gL || !(hooksAvailable[hook_NetVars/8] & (1<<(hook_NetVars%8))))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// stack: tables
|
|
|
|
I_Assert(lua_gettop(gL) > 0);
|
|
|
|
I_Assert(lua_istable(gL, -1));
|
|
|
|
|
2016-03-03 22:30:46 +00:00
|
|
|
// tables becomes an upvalue of archFunc
|
|
|
|
lua_pushvalue(gL, -1);
|
|
|
|
lua_pushcclosure(gL, archFunc, 1);
|
|
|
|
// stack: tables, archFunc
|
|
|
|
|
2016-03-03 22:07:05 +00:00
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_NetVars)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -2); // archFunc
|
|
|
|
LUA_Call(gL, 1);
|
|
|
|
}
|
2016-03-03 22:07:05 +00:00
|
|
|
|
2016-03-03 22:30:46 +00:00
|
|
|
lua_pop(gL, 1); // pop archFunc
|
2016-03-03 22:19:21 +00:00
|
|
|
// stack: tables
|
2016-03-03 22:07:05 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 20:41:22 +00:00
|
|
|
boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing)
|
|
|
|
{
|
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
|
|
|
if (!gL || !(hooksAvailable[hook_MapThingSpawn/8] & (1<<(hook_MapThingSpawn%8))))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
lua_settop(gL, 0);
|
|
|
|
|
|
|
|
// Look for all generic mobj map thing spawn hooks
|
|
|
|
for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_MapThingSpawn)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2017-04-15 20:41:22 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, mo, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, mthing, META_MAPTHING);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2017-04-15 20:41:22 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2017-04-15 20:41:22 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2017-04-15 20:41:22 +00:00
|
|
|
|
|
|
|
for (hookp = mobjhooks[mo->type]; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_MapThingSpawn)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2017-04-15 20:41:22 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, mo, META_MOBJ);
|
|
|
|
LUA_PushUserdata(gL, mthing, META_MAPTHING);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2017-04-15 20:41:22 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2017-04-15 20:41:22 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2017-04-15 20:41:22 +00:00
|
|
|
|
|
|
|
lua_settop(gL, 0);
|
|
|
|
return hooked;
|
|
|
|
}
|
|
|
|
|
2017-10-02 13:08:58 +00:00
|
|
|
// Hook for P_PlayerAfterThink Smiles mobj-following
|
|
|
|
boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
|
|
|
|
{
|
|
|
|
hook_p hookp;
|
|
|
|
boolean hooked = false;
|
|
|
|
if (!gL || !(hooksAvailable[hook_FollowMobj/8] & (1<<(hook_FollowMobj%8))))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
lua_settop(gL, 0);
|
|
|
|
|
|
|
|
for (hookp = playerhooks; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_FollowMobj)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
2017-10-02 13:08:58 +00:00
|
|
|
{
|
2019-06-19 11:28:57 +00:00
|
|
|
LUA_PushUserdata(gL, player, META_PLAYER);
|
|
|
|
LUA_PushUserdata(gL, mobj, META_MOBJ);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
2017-10-02 13:08:58 +00:00
|
|
|
lua_pop(gL, 1);
|
2019-06-19 11:28:57 +00:00
|
|
|
hookp->error = true;
|
|
|
|
continue;
|
2017-10-02 13:08:58 +00:00
|
|
|
}
|
2019-06-19 11:28:57 +00:00
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
hooked = true;
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
2017-10-02 13:08:58 +00:00
|
|
|
|
|
|
|
lua_settop(gL, 0);
|
|
|
|
return hooked;
|
|
|
|
}
|
|
|
|
|
"PlayerCanDamage" hook!
* Takes function(player, mo) input.
* Return TRUE for stating that yes, the player is in a state that can cause contact damage, do with that what you will.
* Return FALSE for stating that no, the player is weak and vulnerable and cannot cause contact damage, do with that what you will.
* Return NIL for allowing the function to continue regular operation.
Fills a different ideological niche than ShouldDamage - that's for determining whether damage dished between two objects should happen, this is for determining which way around damage should be dished when considering a player-object interaction.
Or, in other words, think of it as "ShouldDamage is whether damage that has been requested should be granted, for object-object interaction, while PlayerCanDamage is for whether global player properties should cause damage to enemies and monitors in the first place, like spinning, hammering or stomping."
2019-06-19 11:55:05 +00:00
|
|
|
// Hook for P_PlayerCanDamage
|
|
|
|
UINT8 LUAh_PlayerCanDamage(player_t *player, mobj_t *mobj)
|
|
|
|
{
|
|
|
|
hook_p hookp;
|
|
|
|
UINT8 shouldCollide = 0; // 0 = default, 1 = force yes, 2 = force no.
|
|
|
|
if (!gL || !(hooksAvailable[hook_PlayerCanDamage/8] & (1<<(hook_PlayerCanDamage%8))))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
lua_settop(gL, 0);
|
|
|
|
|
|
|
|
for (hookp = playerhooks; hookp; hookp = hookp->next)
|
|
|
|
{
|
|
|
|
if (hookp->type != hook_PlayerCanDamage)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
|
|
|
{
|
|
|
|
LUA_PushUserdata(gL, player, META_PLAYER);
|
|
|
|
LUA_PushUserdata(gL, mobj, META_MOBJ);
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
if (lua_pcall(gL, 2, 1, 0)) {
|
|
|
|
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_isnil(gL, -1))
|
|
|
|
{ // if nil, leave shouldCollide = 0.
|
|
|
|
if (lua_toboolean(gL, -1))
|
|
|
|
shouldCollide = 1; // Force yes
|
|
|
|
else
|
|
|
|
shouldCollide = 2; // Force no
|
|
|
|
}
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_settop(gL, 0);
|
|
|
|
return shouldCollide;
|
|
|
|
}
|
|
|
|
|
2016-10-21 03:26:41 +00:00
|
|
|
void LUAh_PlayerQuit(player_t *plr, int reason)
|
2016-10-21 02:25:11 +00:00
|
|
|
{
|
|
|
|
hook_p hookp;
|
|
|
|
if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8))))
|
2016-10-21 03:26:41 +00:00
|
|
|
return;
|
2016-10-21 02:25:11 +00:00
|
|
|
|
|
|
|
lua_settop(gL, 0);
|
|
|
|
|
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-06-19 11:28:57 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_PlayerQuit)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lua_gettop(gL) == 0)
|
|
|
|
{
|
|
|
|
LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit
|
|
|
|
lua_pushinteger(gL, reason); // Reason for quitting
|
|
|
|
}
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
lua_pushvalue(gL, -3);
|
|
|
|
LUA_Call(gL, 2);
|
|
|
|
}
|
2016-10-21 02:25:11 +00:00
|
|
|
|
|
|
|
lua_settop(gL, 0);
|
|
|
|
}
|
|
|
|
|
2019-10-14 00:50:46 +00:00
|
|
|
// Hook for Y_Ticker
|
|
|
|
void LUAh_IntermissionThinker(void)
|
|
|
|
{
|
|
|
|
hook_p hookp;
|
|
|
|
if (!gL || !(hooksAvailable[hook_IntermissionThinker/8] & (1<<(hook_IntermissionThinker%8))))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
2019-10-15 01:47:20 +00:00
|
|
|
{
|
|
|
|
if (hookp->type != hook_IntermissionThinker)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
|
|
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
|
|
|
if (lua_pcall(gL, 0, 0, 0)) {
|
|
|
|
if (!hookp->error || cv_debug & DBG_LUA)
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
|
|
|
lua_pop(gL, 1);
|
|
|
|
hookp->error = true;
|
2019-10-14 00:50:46 +00:00
|
|
|
}
|
2019-10-15 01:47:20 +00:00
|
|
|
}
|
2019-10-14 00:50:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
#endif
|