From c2aa6d4de6f4919ac9d4218844d3cf154cadd4e5 Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Sun, 13 Jan 2019 14:40:48 +0100 Subject: [PATCH 1/3] Expose some more Kart functions, freeplay and rankings bumpers are now hud stuff you can toggle, + experimental playercmd hook --- src/g_game.c | 8 +++++ src/k_kart.c | 44 +++++++++++++++++--------- src/k_kart.h | 7 +++++ src/lua_baselib.c | 77 +++++++++++++++++++++++++++++++++++++++++++-- src/lua_hook.h | 6 ++++ src/lua_hooklib.c | 42 +++++++++++++++++++++++++ src/lua_hud.h | 2 ++ src/lua_hudlib.c | 17 ++++++++++ src/lua_infolib.c | 13 ++++++++ src/lua_maplib.c | 7 +++++ src/lua_mobjlib.c | 6 ++++ src/lua_playerlib.c | 8 +++++ 12 files changed, 221 insertions(+), 16 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 1e0c7e46..d93a2e9f 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1612,10 +1612,18 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) } } + // Lua: Allow this hook to overwrite ticcmd. + // Be aware that you can't actually write anything inside the player with this hook, only cmd may be altered. +#ifdef HAVE_BLUA + if (playeringame[consoleplayer]) // safe to assume we can't do anything if consoleplayer isn't in the game. + LUAh_PlayerCmd(player, cmd); +#endif + //Reset away view if a command is given. if ((cmd->forwardmove || cmd->sidemove || cmd->buttons) && displayplayer != consoleplayer && ssplayer == 1) displayplayer = consoleplayer; + } // User has designated that they want diff --git a/src/k_kart.c b/src/k_kart.c index 320105ef..bd4e1394 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1548,7 +1548,7 @@ static void K_RegularVoiceTimers(player_t *player) player->kartstuff[k_tauntvoices] = 4*TICRATE; } -static void K_PlayAttackTaunt(mobj_t *source) +void K_PlayAttackTaunt(mobj_t *source) { sfxenum_t pick = P_RandomKey(2); // Gotta roll the RNG every time this is called for sync reasons boolean tasteful = (!source->player || !source->player->kartstuff[k_tauntvoices]); @@ -1562,7 +1562,7 @@ static void K_PlayAttackTaunt(mobj_t *source) K_TauntVoiceTimers(source->player); } -static void K_PlayBoostTaunt(mobj_t *source) +void K_PlayBoostTaunt(mobj_t *source) { sfxenum_t pick = P_RandomKey(2); // Gotta roll the RNG every time this is called for sync reasons boolean tasteful = (!source->player || !source->player->kartstuff[k_tauntvoices]); @@ -1576,7 +1576,7 @@ static void K_PlayBoostTaunt(mobj_t *source) K_TauntVoiceTimers(source->player); } -static void K_PlayOvertakeSound(mobj_t *source) +void K_PlayOvertakeSound(mobj_t *source) { boolean tasteful = (!source->player || !source->player->kartstuff[k_voices]); @@ -1596,7 +1596,7 @@ static void K_PlayOvertakeSound(mobj_t *source) K_RegularVoiceTimers(source->player); } -static void K_PlayHitEmSound(mobj_t *source) +void K_PlayHitEmSound(mobj_t *source) { if (cv_kartvoices.value) S_StartSound(source, sfx_khitem); @@ -1606,7 +1606,7 @@ static void K_PlayHitEmSound(mobj_t *source) K_RegularVoiceTimers(source->player); } -static void K_PlayPowerGloatSound(mobj_t *source) +void K_PlayPowerGloatSound(mobj_t *source) { if (cv_kartvoices.value) S_StartSound(source, sfx_kgloat); @@ -4670,7 +4670,7 @@ static void K_KartDrift(player_t *player, boolean onground) player->kartstuff[k_driftend] = 0; } - + // Incease/decrease the drift value to continue drifting in that direction if (player->kartstuff[k_spinouttimer] == 0 && player->kartstuff[k_jmp] == 1 && onground && player->kartstuff[k_drift] != 0) @@ -6933,15 +6933,23 @@ static boolean K_drawKartPositionFaces(void) colormap = R_GetTranslationColormap(players[rankplayer[i]].skin, players[rankplayer[i]].mo->color, GTC_CACHE); V_DrawMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, facerankprefix[players[rankplayer[i]].skin], colormap); - if (G_BattleGametype() && players[rankplayer[i]].kartstuff[k_bumper] > 0) + +#ifdef HAVE_BLUA + if (LUA_HudEnabled(hud_battlebumpers)) { - V_DrawMappedPatch(bumperx-2, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_tinybumper[0], colormap); - for (j = 1; j < players[rankplayer[i]].kartstuff[k_bumper]; j++) +#endif + if (G_BattleGametype() && players[rankplayer[i]].kartstuff[k_bumper] > 0) { - bumperx += 5; - V_DrawMappedPatch(bumperx, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_tinybumper[1], colormap); + V_DrawMappedPatch(bumperx-2, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_tinybumper[0], colormap); + for (j = 1; j < players[rankplayer[i]].kartstuff[k_bumper]; j++) + { + bumperx += 5; + V_DrawMappedPatch(bumperx, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_tinybumper[1], colormap); + } } - } +#ifdef HAVE_BLUA + } // A new level of stupidity: checking if lua is enabled to close a bracket. :Fascinating: +#endif } if (i == strank) @@ -7641,7 +7649,10 @@ static void K_drawBattleFullscreen(void) return; } - K_drawKartFreePlay(leveltime); +#ifdef HAVE_BLUA + if (LUA_HudEnabled(hud_freeplay)) +#endif + K_drawKartFreePlay(leveltime); } } @@ -8263,7 +8274,12 @@ void K_drawKartHUD(void) // Draw FREE PLAY. if (isfreeplay && !stplyr->spectator && timeinmap > 113) - K_drawKartFreePlay(leveltime); + { +#ifdef HAVE_BLUA + if (LUA_HudEnabled(hud_freeplay)) +#endif + K_drawKartFreePlay(leveltime); + } if (cv_kartdebugdistribution.value) K_drawDistributionDebugger(); diff --git a/src/k_kart.h b/src/k_kart.h index fed490db..aefc20bb 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -63,6 +63,13 @@ void K_CalculateBattleWanted(void); void K_CheckBumpers(void); void K_CheckSpectateStatus(void); +// sound stuff for lua +void K_PlayAttackTaunt(mobj_t *source); +void K_PlayBoostTaunt(mobj_t *source); +void K_PlayOvertakeSound(mobj_t *source); +void K_PlayHitEmSound(mobj_t *source); +void K_PlayPowerGloatSound(mobj_t *source); + const char *K_GetItemPatch(UINT8 item, boolean tiny); INT32 K_calcSplitFlags(INT32 snapflags); void K_LoadKartHUDGraphics(void); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index c862ec26..b0231e39 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -31,9 +31,10 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#include "lua_hook.h" // hook_cmd_running -#define NOHUD if (hud_running) return luaL_error(L, "HUD rendering code should not call this function!"); - +#define NOHUD if (hud_running) return luaL_error(L, "HUD rendering code should not call this function!"); else if (hook_cmd_running) return luaL_error(L, "CMD Building code should not call this function!"); +// Yes technically cmd hook isn't a hud but whatever, this avoids having 2 defines for virtually the same thing. boolean luaL_checkboolean(lua_State *L, int narg) { luaL_checktype(L, narg, LUA_TBOOLEAN); @@ -2141,6 +2142,72 @@ static int lib_gTicsToMilliseconds(lua_State *L) // K_KART //////////// +// Seriously, why weren't those exposed before? +static int lib_kAttackSound(lua_State *L) +{ + mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + NOHUD + if (!mobj->player) + return luaL_error(L, "K_PlayAttackTaunt: mobj_t isn't a player object."); //Nothing bad would happen if we let it run the func, but telling why it ain't doing anything is helpful. + K_PlayAttackTaunt(mobj); + return 0; +} + +static int lib_kBoostSound(lua_State *L) +{ + mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + NOHUD + if (!mobj->player) + return luaL_error(L, "K_PlayBoostTaunt: mobj_t isn't a player object."); //Nothing bad would happen if we let it run the func, but telling why it ain't doing anything is helpful. + K_PlayBoostTaunt(mobj); + return 0; +} + +static int lib_kOvertakeSound(lua_State *L) +{ + mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + NOHUD + if (!mobj->player) + return luaL_error(L, "K_PlayOvertakeSound: mobj_t isn't a player object."); //Nothing bad would happen if we let it run the func, but telling why it ain't doing anything is helpful. + K_PlayOvertakeSound(mobj); + return 0; +} + +static int lib_kHitEmSound(lua_State *L) +{ + mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + NOHUD + if (!mobj->player) + return luaL_error(L, "K_PlayHitEmSound: mobj_t isn't a player object."); //Nothing bad would happen if we let it run the func, but telling why it ain't doing anything is helpful. + K_PlayHitEmSound(mobj); + return 0; +} + +static int lib_kGloatSound(lua_State *L) +{ + mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + NOHUD + if (!mobj->player) + return luaL_error(L, "K_PlayPowerGloatSound: mobj_t isn't a player object."); //Nothing bad would happen if we let it run the func, but telling why it ain't doing anything is helpful. + K_PlayPowerGloatSound(mobj); + return 0; +} + +static int lib_kLossSound(lua_State *L) +{ + mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); // let's require a mobj for consistency with the other functions + sfxenum_t sfx_id; + NOHUD + if (!mobj->player) + return luaL_error(L, "K_PlayLossSound: mobj_t isn't a player object."); + + sfx_id = ((skin_t *)mobj->skin)->soundsid[S_sfx[sfx_klose].skinsound]; + S_StartSound(mobj, sfx_id); + return 0; +} + +// Note: Pain, Death and Victory are already exposed. + static int lib_kGetKartColorByName(lua_State *L) { const char *name = luaL_checkstring(L, 1); @@ -2708,6 +2775,12 @@ static luaL_Reg lib[] = { {"G_TicsToMilliseconds",lib_gTicsToMilliseconds}, // k_kart + {"K_PlayAttackTaunt", lib_kAttackSound}, + {"K_PlayBoostTaunt", lib_kBoostSound}, + {"K_PlayPowerGloatSund", lib_kGloatSound}, + {"K_PlayOvertakeSound", lib_kOvertakeSound}, + {"K_PlayLossSound", lib_kLossSound}, + {"K_PlayHitEmSound", lib_kHitEmSound}, {"K_GetKartColorByName",lib_kGetKartColorByName}, {"K_IsPlayerLosing",lib_kIsPlayerLosing}, {"K_IsPlayerWanted",lib_kIsPlayerWanted}, diff --git a/src/lua_hook.h b/src/lua_hook.h index 2c9cd346..126e7e40 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -50,11 +50,14 @@ enum hook { hook_PlayerSpin, //SRB2KART hook_PlayerExplode, //SRB2KART hook_PlayerSquish, //SRB2KART + hook_PlayerCmd, //SRB2KART hook_MAX // last hook }; extern const char *const hookNames[]; +extern boolean hook_cmd_running; // This is used by PlayerCmd and lua_playerlib to prevent anything from being wirtten to player while we run PlayerCmd. + void LUAh_MapChange(INT16 mapnumber); // Hook for map change (before load) void LUAh_MapLoad(void); // Hook for map load void LUAh_PlayerJoin(int playernum); // Hook for Got_AddPlayer @@ -93,4 +96,7 @@ UINT8 LUAh_ShouldSquish(player_t *player, mobj_t *inflictor, mobj_t *source); // boolean LUAh_PlayerSpin(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_SpinPlayer. Allows Lua to execute code and/or overwrite its behavior. boolean LUAh_PlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_ExplodePlayer. Allows Lua to execute code and/or overwrite its behavior. boolean LUAh_PlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_SquishPlayer. Allows Lua to execute code and/or overwrite its behavior. + +boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd); // Allows to write to player cmd before the game does anything with them. + #endif diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 13ad03d3..1a1d4ed6 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -61,6 +61,7 @@ const char *const hookNames[hook_MAX+1] = { "PlayerSpin", "PlayerExplode", "PlayerSquish", + "PlayerCmd", NULL }; @@ -877,6 +878,47 @@ boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd) return hooked; } +// Hook for G_BuildTicCmd +boolean hook_cmd_running = false; +boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd) +{ + hook_p hookp; + boolean hooked = false; + if (!gL || !(hooksAvailable[hook_PlayerCmd/8] & (1<<(hook_PlayerCmd%8)))) + return false; + + lua_settop(gL, 0); + + for (hookp = roothook; hookp; hookp = hookp->next) + if (hookp->type == hook_PlayerCmd) + { + hook_cmd_running = true; + if (lua_gettop(gL) == 0) + { + LUA_PushUserdata(gL, player, 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)); + lua_pop(gL, 1); + hookp->error = true; + continue; + } + if (lua_toboolean(gL, -1)) + hooked = true; + lua_pop(gL, 1); + hook_cmd_running = false; + } + + lua_settop(gL, 0); + return hooked; +} + // Hook for B_BuildTailsTiccmd by skin name boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) { diff --git a/src/lua_hud.h b/src/lua_hud.h index 3216ab15..4fbbbace 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -20,8 +20,10 @@ enum hud { hud_item, hud_position, hud_minirankings, // Rankings to the left + hud_battlebumpers, // mini rankings battle bumpers. hud_wanted, hud_speedometer, + hud_freeplay, hud_rankings, // Tab rankings hud_MAX diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 353aebb2..ca952a00 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -45,8 +45,10 @@ static const char *const hud_disable_options[] = { "item", "position", "minirankings", // Gametype rankings to the left + "battlerankingsbumpers", // bumper drawer for battle. Useful if you want to make a custom battle gamemode without bumpers being involved. "wanted", "speedometer", + "freeplay", "rankings", NULL}; @@ -482,6 +484,20 @@ static int libd_drawString(lua_State *L) return 0; } +static int libd_drawKartString(lua_State *L) +{ + fixed_t x = luaL_checkinteger(L, 1); + fixed_t y = luaL_checkinteger(L, 2); + const char *str = luaL_checkstring(L, 3); + INT32 flags = luaL_optinteger(L, 4, V_ALLOWLOWERCASE); + + flags &= ~V_PARAMMASK; // Don't let crashes happen. + + HUDONLY + V_DrawKartString(x, y, flags, str); + return 0; +} + static int libd_stringWidth(lua_State *L) { const char *str = luaL_checkstring(L, 1); @@ -593,6 +609,7 @@ static luaL_Reg lib_draw[] = { {"drawFill", libd_drawFill}, {"fadeScreen", libd_fadeScreen}, {"drawString", libd_drawString}, + {"drawKartString", libd_drawKartString}, {"stringWidth", libd_stringWidth}, {"getColormap", libd_getColormap}, {"width", libd_width}, diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 9b22170f..d8659a7e 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -22,6 +22,7 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#include "lua_hook.h" // cmd errors boolean LUA_CallAction(const char *action, mobj_t *actor); state_t *astate; @@ -169,6 +170,8 @@ static int lib_setState(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter states in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter states in BuildCMD code!"); // clear the state to start with, in case of missing table elements memset(state,0,sizeof(state_t)); @@ -378,6 +381,8 @@ static int state_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter states in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter states in BuildCMD code!"); if (fastcmp(field,"sprite")) { value = luaL_checknumber(L, 3); @@ -466,6 +471,8 @@ static int lib_setMobjInfo(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter mobjinfo in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter mobjinfo in BuildCMD code!"); // clear the mobjinfo to start with, in case of missing table elements memset(info,0,sizeof(mobjinfo_t)); @@ -633,6 +640,8 @@ static int mobjinfo_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter mobjinfo in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter mobjinfo in BuildCMD code!"); I_Assert(info != NULL); I_Assert(info >= mobjinfo); @@ -755,6 +764,8 @@ static int lib_setSfxInfo(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter sfxinfo in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter sfxinfo in BuildCMD code!"); lua_pushnil(L); while (lua_next(L, 1)) { @@ -830,6 +841,8 @@ static int sfxinfo_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter S_sfx in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter S_sfx in BuildCMD code!"); I_Assert(sfx != NULL); diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 7599b261..0bb9a99d 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -24,6 +24,7 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#include "lua_hook.h" // cmd errors #include "dehacked.h" #include "fastcmp.h" @@ -484,6 +485,8 @@ static int sector_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter sector_t in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter sector_t in BuildCMD code!"); switch(field) { @@ -1174,6 +1177,8 @@ static int ffloor_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter ffloor_t in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter ffloor_t in BuildCMD code!"); switch(field) { @@ -1303,6 +1308,8 @@ static int slope_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter pslope_t in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter pslope_t in BuildCMD code!"); switch(field) // todo: reorganize this shit { diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 34aba0a3..b56538d0 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -21,6 +21,7 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#include "lua_hook.h" // cmd errors static const char *const array_opt[] ={"iterate",NULL}; @@ -391,6 +392,9 @@ static int mobj_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter mobj_t in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter mobj_t in BuildCMD code!"); + switch(field) { case mobj_valid: @@ -756,6 +760,8 @@ static int mapthing_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter mapthing_t in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter mapthing_t in BuildCMD code!"); if(fastcmp(field,"x")) mt->x = (INT16)luaL_checkinteger(L, 3); diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 067124ba..5f136fc1 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -21,6 +21,7 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#include "lua_hook.h" // hook_cmd_running static int lib_iteratePlayers(lua_State *L) { @@ -356,6 +357,9 @@ static int player_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter player_t in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter player_t in BuildCMD code!"); + if (fastcmp(field,"mo")) { mobj_t *newmo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); plr->mo->player = NULL; // remove player pointer from old mobj @@ -667,6 +671,8 @@ static int power_set(lua_State *L) return luaL_error(L, LUA_QL("powertype_t") " cannot be %u", p); if (hud_running) return luaL_error(L, "Do not alter player_t in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter player_t in BuildCMD code!"); powers[p] = i; return 0; } @@ -699,6 +705,8 @@ static int kartstuff_set(lua_State *L) return luaL_error(L, LUA_QL("kartstufftype_t") " cannot be %u", ks); if (hud_running) return luaL_error(L, "Do not alter player_t in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter player_t in BuildCMD code!"); kartstuff[ks] = i; return 0; } From 148bd140c23906c5fe6f8666392ab7410d64b206 Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Sun, 13 Jan 2019 20:16:53 +0100 Subject: [PATCH 2/3] hook_cmd_running around the loop rather than inside --- src/lua_hooklib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 1a1d4ed6..5a95877e 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -889,10 +889,10 @@ boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd) lua_settop(gL, 0); + hook_cmd_running = true; for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerCmd) { - hook_cmd_running = true; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -912,9 +912,9 @@ boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd) if (lua_toboolean(gL, -1)) hooked = true; lua_pop(gL, 1); - hook_cmd_running = false; } + hook_cmd_running = false; lua_settop(gL, 0); return hooked; } From 72133b74985f9862669ab8dab46ed80cd7b45343 Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Sat, 26 Jan 2019 16:55:26 +0100 Subject: [PATCH 3/3] No more ghetto check, and some more descriptive comments on the Hook --- src/g_game.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index d93a2e9f..58787495 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1612,10 +1612,18 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) } } - // Lua: Allow this hook to overwrite ticcmd. - // Be aware that you can't actually write anything inside the player with this hook, only cmd may be altered. + /* Lua: Allow this hook to overwrite ticcmd. + We check if we're actually in a level because for some reason this Hook would run in menus and on the titlescreen otherwise. + Be aware that within this hook, nothing but this player's cmd can be edited (otherwise we'd run in some pretty bad synching problems since this is clientsided, or something) + + Possible usages for this are: + -Forcing the player to perform an action, which could otherwise require terrible, terrible hacking to replicate. + -Preventing the player to perform an action, which would ALSO require some weirdo hacks. + -Making some galaxy brain autopilot Lua if you're a masochist + -Making a Mario Kart 8 Deluxe tier baby mode that steers you away from walls and whatnot. You know what, do what you want! + */ #ifdef HAVE_BLUA - if (playeringame[consoleplayer]) // safe to assume we can't do anything if consoleplayer isn't in the game. + if (gamestate == GS_LEVEL) LUAh_PlayerCmd(player, cmd); #endif