mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 09:11:48 +00:00
Implemented MusicChange lua hook
# Conflicts: # src/lua_hook.h # src/lua_hooklib.c
This commit is contained in:
parent
79531b9683
commit
d14eedd700
3 changed files with 56 additions and 4 deletions
|
@ -48,6 +48,7 @@ enum hook {
|
||||||
hook_MobjMoveBlocked,
|
hook_MobjMoveBlocked,
|
||||||
hook_MapThingSpawn,
|
hook_MapThingSpawn,
|
||||||
hook_FollowMobj,
|
hook_FollowMobj,
|
||||||
|
hook_MusicChange,
|
||||||
|
|
||||||
hook_MAX // last hook
|
hook_MAX // last hook
|
||||||
};
|
};
|
||||||
|
@ -87,5 +88,6 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8
|
||||||
#define LUAh_MobjMoveBlocked(mo) LUAh_MobjHook(mo, hook_MobjMoveBlocked) // Hook for P_XYMovement (when movement is blocked)
|
#define LUAh_MobjMoveBlocked(mo) LUAh_MobjHook(mo, hook_MobjMoveBlocked) // 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_MapThingSpawn(mobj_t *mo, mapthing_t *mthing); // Hook for P_SpawnMapThing by mobj type
|
||||||
boolean LUAh_FollowMobj(player_t *player, mobj_t *mo); // Hook for P_PlayerAfterThink Smiles mobj-following
|
boolean LUAh_FollowMobj(player_t *player, mobj_t *mo); // Hook for P_PlayerAfterThink Smiles mobj-following
|
||||||
|
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic); // Hook for music changes
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -59,6 +59,7 @@ const char *const hookNames[hook_MAX+1] = {
|
||||||
"MobjMoveBlocked",
|
"MobjMoveBlocked",
|
||||||
"MapThingSpawn",
|
"MapThingSpawn",
|
||||||
"FollowMobj",
|
"FollowMobj",
|
||||||
|
"MusicChange",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1191,5 +1192,41 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
|
||||||
lua_settop(gL, 0);
|
lua_settop(gL, 0);
|
||||||
return hooked;
|
return hooked;
|
||||||
}
|
}
|
||||||
|
// Hook for music changes
|
||||||
|
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic) // UINT16 mflags, boolean looping)
|
||||||
|
{
|
||||||
|
hook_p hookp;
|
||||||
|
boolean hooked = false;
|
||||||
|
|
||||||
|
strncpy(newmusic, newname, 7);
|
||||||
|
|
||||||
|
if (!gL || !(hooksAvailable[hook_MusicChange/8] & (1<<(hook_MusicChange%8))))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua_settop(gL, 0);
|
||||||
|
|
||||||
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
||||||
|
if (hookp->type == hook_MusicChange)
|
||||||
|
{
|
||||||
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||||
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||||
|
lua_pushstring(gL, oldname);
|
||||||
|
lua_pushstring(gL, newname);
|
||||||
|
if (lua_pcall(gL, 2, 1, 0)) {
|
||||||
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
|
||||||
|
lua_pop(gL, 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (lua_isboolean(gL, -1) && lua_toboolean(gL, -1))
|
||||||
|
hooked = true;
|
||||||
|
else if (lua_isstring(gL, -1))
|
||||||
|
strncpy(newmusic, lua_tostring(gL, -1), 7);
|
||||||
|
lua_pop(gL, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_settop(gL, 0);
|
||||||
|
newmusic[6] = 0;
|
||||||
|
return hooked;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,6 +38,10 @@ extern INT32 msg_id;
|
||||||
#include "p_local.h" // camera info
|
#include "p_local.h" // camera info
|
||||||
#include "fastcmp.h"
|
#include "fastcmp.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_BLUA
|
||||||
|
#include "lua_hook.h" // MusicChange hook
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HW3SOUND
|
#ifdef HW3SOUND
|
||||||
// 3D Sound Interface
|
// 3D Sound Interface
|
||||||
#include "hardware/hw3sound.h"
|
#include "hardware/hw3sound.h"
|
||||||
|
@ -1380,19 +1384,28 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
|
||||||
if ((nomidimusic || music_disabled) && (nodigimusic || digital_disabled))
|
if ((nomidimusic || music_disabled) && (nodigimusic || digital_disabled))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
char newmusic[7];
|
||||||
|
#ifdef HAVE_BLUA
|
||||||
|
if(LUAh_MusicChange(music_name, mmusic, newmusic)) // todo: mflags and looping?
|
||||||
|
return;
|
||||||
|
#else
|
||||||
|
strncpy(newmusic, mmusic, 7);
|
||||||
|
#endif
|
||||||
|
newmusic[6] = 0;
|
||||||
|
|
||||||
// No Music (empty string)
|
// No Music (empty string)
|
||||||
if (mmusic[0] == 0)
|
if (newmusic[0] == 0)
|
||||||
{
|
{
|
||||||
S_StopMusic();
|
S_StopMusic();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(music_name, mmusic, 6))
|
if (strncmp(music_name, newmusic, 6))
|
||||||
{
|
{
|
||||||
S_StopMusic(); // shutdown old music
|
S_StopMusic(); // shutdown old music
|
||||||
if (!S_DigMusic(mmusic, looping) && !S_MIDIMusic(mmusic, looping))
|
if (!S_DigMusic(newmusic, looping) && !S_MIDIMusic(newmusic, looping))
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic);
|
CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), newmusic);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue