From 359befd85722f341e44822ad434e75741d09d541 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 28 May 2025 23:27:30 +0300 Subject: [PATCH] Add MusicCredit lua hook --- src/lua_hook.h | 2 ++ src/lua_hooklib.c | 12 ++++++++++++ src/s_sound.c | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 45237aa80..c31a58a67 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -55,6 +55,7 @@ X (PlayerQuit),\ X (PlayerThink),/* P_PlayerThink */\ X (MusicChange),\ + X (MusicCredit),\ X (ShouldSpin),/*SRB2KART*/\ X (ShouldExplode),/*SRB2KART*/\ X (ShouldSquish),/*SRB2KART*/\ @@ -130,6 +131,7 @@ int LUA_HookPlayerCanDamage(player_t *, mobj_t *); void LUA_HookPlayerQuit(player_t *, int); int LUA_HookPlayerCmd(player_t *, ticcmd_t *); int LUA_HookMusicChange(const char *oldname, struct MusicChange *); +int LUA_HookMusicCredit(musicdef_t *musicdef); int LUA_HookShouldSpin(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be spun out? int LUA_HookShouldExplode(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be exploded? diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index a0f795985..1ef02b886 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -1065,6 +1065,18 @@ int LUA_HookMusicChange(const char *oldname, struct MusicChange *param) return hook.status; } +int LUA_HookMusicCredit(musicdef_t *musicdef) +{ + Hook_State hook; + if (prepare_hook(&hook, 0, HOOK(MusicCredit))) + { + LUA_PushUserdata(gL, musicdef, META_MUSICDEF); + call_hooks(&hook, 1, res_true); + } + + return hook.status; +} + static int kartdamage_hook ( player_t *player, diff --git a/src/s_sound.c b/src/s_sound.c index 922d864d5..ab9a1a2d7 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -32,6 +32,7 @@ #include "m_menu.h" // bird music stuff #include "lua_hook.h" // MusicChange hook +#include "lua_hud.h" // LUA_HudEnabled(hud_musiccredit) static boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); static void SetChannelsNum(void); @@ -1452,7 +1453,7 @@ void S_ShowSpecifiedMusicCredit(const char *musname) def = S_FindMusicCredit(musname); - if (def) + if (def && !LUA_HookMusicCredit(def)) { cursongcredit.def = def; cursongcredit.anim = 5*TICRATE;