Merge branch 'gamequit-hook' into 'next'

GameQuit Hook

See merge request STJr/SRB2!847
This commit is contained in:
James R 2020-06-25 12:45:20 -04:00
commit 0435acd516
6 changed files with 48 additions and 1 deletions

View file

@ -3576,6 +3576,8 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
if (pnum == consoleplayer)
{
if (Playing())
LUAh_GameQuit();
#ifdef DUMPCONSISTENCY
if (msg == KICK_MSG_CON_FAIL) SV_SavedGame();
#endif
@ -4244,6 +4246,8 @@ static void HandleConnect(SINT8 node)
static void HandleShutdown(SINT8 node)
{
(void)node;
if (Playing())
LUAh_GameQuit();
D_QuitNetGame();
CL_Reset();
D_StartTitle();
@ -4258,6 +4262,8 @@ static void HandleShutdown(SINT8 node)
static void HandleTimeout(SINT8 node)
{
(void)node;
if (Playing())
LUAh_GameQuit();
D_QuitNetGame();
CL_Reset();
D_StartTitle();

View file

@ -3570,6 +3570,8 @@ static void Command_Playintro_f(void)
*/
FUNCNORETURN static ATTRNORETURN void Command_Quit_f(void)
{
if (Playing())
LUAh_GameQuit();
I_Quit();
}
@ -4231,6 +4233,9 @@ void Command_ExitGame_f(void)
{
INT32 i;
if (Playing())
LUAh_GameQuit();
D_QuitNetGame();
CL_Reset();
CV_ClearChangedFlags();

View file

@ -58,6 +58,7 @@ enum hook {
hook_SeenPlayer,
hook_PlayerThink,
hook_ShouldJingleContinue,
hook_GameQuit,
hook_MAX // last hook
};
@ -112,3 +113,4 @@ boolean LUAh_SeenPlayer(player_t *player, player_t *seenfriend); // Hook for MT_
#endif
#define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink
boolean LUAh_ShouldJingleContinue(player_t *player, const char *musname); // Hook for whether a jingle of the given music should continue playing
void LUAh_GameQuit(void); // Hook for game quitting

View file

@ -70,6 +70,7 @@ const char *const hookNames[hook_MAX+1] = {
"SeenPlayer",
"PlayerThink",
"ShouldJingleContinue",
"GameQuit",
NULL
};
@ -1769,3 +1770,29 @@ boolean LUAh_ShouldJingleContinue(player_t *player, const char *musname)
return keepplaying;
}
// Hook for game quitting
void LUAh_GameQuit(void)
{
hook_p hookp;
if (!gL || !(hooksAvailable[hook_GameQuit/8] & (1<<(hook_GameQuit%8))))
return;
lua_pushcfunction(gL, LUA_GetErrorMessage);
for (hookp = roothook; hookp; hookp = hookp->next)
{
if (hookp->type != hook_GameQuit)
continue;
PushHook(gL, hookp);
if (lua_pcall(gL, 0, 0, 1)) {
if (!hookp->error || cv_debug & DBG_LUA)
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
lua_pop(gL, 1);
hookp->error = true;
}
}
lua_pop(gL, 1); // Pop error handler
}

View file

@ -44,6 +44,7 @@
#include "p_local.h"
#include "p_setup.h"
#include "f_finale.h"
#include "lua_hook.h"
#ifdef HWRENDER
#include "hardware/hw_main.h"
@ -6918,6 +6919,8 @@ static void M_SelectableClearMenus(INT32 choice)
static void M_UltimateCheat(INT32 choice)
{
(void)choice;
if (Playing())
LUAh_GameQuit();
I_Quit();
}
@ -13196,6 +13199,8 @@ void M_QuitResponse(INT32 ch)
if (ch != 'y' && ch != KEY_ENTER)
return;
if (Playing())
LUAh_GameQuit();
if (!(netgame || cv_debug))
{
S_ResetCaptions();

View file

@ -73,6 +73,7 @@
#include "../console.h"
#include "../command.h"
#include "../r_main.h"
#include "../lua_hook.h"
#include "sdlmain.h"
#ifdef HWRENDER
#include "../hardware/hw_main.h"
@ -1057,8 +1058,9 @@ void I_GetEvent(void)
M_SetupJoystickMenu(0);
break;
case SDL_QUIT:
if (Playing())
LUAh_GameQuit();
I_Quit();
M_QuitResponse('y');
break;
}
}