Revise LUAh_MusicChange hook

This commit is contained in:
mazmazz 2018-08-28 09:42:13 -04:00
parent 9f3549e5e1
commit 0bea5729a7
3 changed files with 7 additions and 12 deletions

View file

@ -89,7 +89,7 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8
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
#ifdef HAVE_LUA_MUSICPLUS
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic, UINT16 *mflags, boolean *looping,
boolean LUAh_MusicChange(const char *oldname, char *newname, UINT16 *mflags, boolean *looping,
UINT32 *position, UINT32 *prefadems, UINT32 *fadeinms); // Hook for music changes
#endif

View file

@ -1196,14 +1196,12 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
#ifdef HAVE_LUA_MUSICPLUS
// Hook for music changes
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic, UINT16 *mflags, boolean *looping,
boolean LUAh_MusicChange(const char *oldname, char *newname, UINT16 *mflags, boolean *looping,
UINT32 *position, UINT32 *prefadems, UINT32 *fadeinms)
{
hook_p hookp;
boolean hooked = false;
strncpy(newmusic, newname, 7);
if (!gL || !(hooksAvailable[hook_MusicChange/8] & (1<<(hook_MusicChange%8))))
return false;
@ -1231,7 +1229,7 @@ boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusi
if (lua_isboolean(gL, -6) && lua_toboolean(gL, -6))
hooked = true;
else if (lua_isstring(gL, -6))
strncpy(newmusic, lua_tostring(gL, -6), 7);
strncpy(newname, lua_tostring(gL, -6), 7);
// output 2: mflags override
if (lua_isnumber(gL, -5))
*mflags = lua_tonumber(gL, -5);
@ -1252,7 +1250,7 @@ boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusi
}
lua_settop(gL, 0);
newmusic[6] = 0;
newname[6] = 0;
return hooked;
}

View file

@ -1553,14 +1553,11 @@ void S_ChangeMusicAdvanced(const char *mmusic, UINT16 mflags, boolean looping, U
return;
char newmusic[7];
#if defined(HAVE_BLUA) && defined(HAVE_LUA_MUSICPLUS)
if(LUAh_MusicChange(music_name, mmusic, newmusic, &mflags, &looping, &position, &prefadems, &fadeinms))
return;
#else
strncpy(newmusic, mmusic, 7);
#if defined(HAVE_BLUA) && defined(HAVE_LUA_MUSICPLUS)
if(LUAh_MusicChange(music_name, newmusic, &mflags, &looping, &position, &prefadems, &fadeinms))
return;
#endif
newmusic[6] = 0;
// No Music (empty string)