Add HOOK_ON_PAUSE_EXIT

This commit is contained in:
MysterD 2022-03-25 23:06:14 -07:00
parent c0b6590fcd
commit 322e4983ae
7 changed files with 36 additions and 3 deletions

View file

@ -5419,7 +5419,10 @@ HOOK_ON_OBJECT_UNLOAD = 14
HOOK_ON_SYNC_OBJECT_UNLOAD = 15
--- @type LuaHookedEventType
HOOK_MAX = 16
HOOK_ON_PAUSE_EXIT = 16
--- @type LuaHookedEventType
HOOK_MAX = 17
--- @class ModelExtendedId

View file

@ -1920,7 +1920,8 @@
| HOOK_ON_SYNC_VALID | 13 |
| HOOK_ON_OBJECT_UNLOAD | 14 |
| HOOK_ON_SYNC_OBJECT_UNLOAD | 15 |
| HOOK_MAX | 16 |
| HOOK_ON_PAUSE_EXIT | 16 |
| HOOK_MAX | 17 |
[:arrow_up_small:](#)

View file

@ -102,6 +102,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| HOOK_ON_SYNC_VALID | Called when the current area is synchronized | None |
| HOOK_ON_OBJECT_UNLOAD | Called when any object is unloaded | [Object](structs.md#Object) unloadedObject |
| HOOK_ON_SYNC_OBJECT_UNLOAD | Called when any networked object is unloaded | [Object](structs.md#Object) unloadedObject |
| HOOK_ON_PAUSE_EXIT | Called when the local player exits through the pause screen | `boolean` usedExitToCastle |
### Parameters

View file

@ -1152,6 +1152,8 @@ s32 play_mode_normal(void) {
return 0;
}
#include <stdio.h> // DO NOT COMMIT
s32 play_mode_paused(void) {
if (gPauseScreenMode == 0) {
set_menu_mode(RENDER_PAUSE_SCREEN);
@ -1162,6 +1164,7 @@ s32 play_mode_paused(void) {
} else if (gPauseScreenMode == 2) {
level_trigger_warp(&gMarioStates[0], WARP_OP_EXIT);
set_play_mode(PLAY_MODE_NORMAL);
smlua_call_event_hooks_bool_param(HOOK_ON_PAUSE_EXIT, false);
} else if (gPauseScreenMode == 3) {
// Exit level
if (gDebugLevelSelect) {
@ -1172,6 +1175,7 @@ s32 play_mode_paused(void) {
gSavedCourseNum = COURSE_NONE;
}
set_play_mode(PLAY_MODE_CHANGE_LEVEL);
smlua_call_event_hooks_bool_param(HOOK_ON_PAUSE_EXIT, true);
} /* else if (gPauseScreenMode == 4) {
// We should only be getting "int 4" to here
initiate_warp(LEVEL_CASTLE, 1, 0x1F, 0);

View file

@ -1948,7 +1948,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_SYNC_VALID = 13\n"
"HOOK_ON_OBJECT_UNLOAD = 14\n"
"HOOK_ON_SYNC_OBJECT_UNLOAD = 15\n"
"HOOK_MAX = 16\n"
"HOOK_ON_PAUSE_EXIT = 16\n"
"HOOK_MAX = 17\n"
"E_MODEL_NONE = 0\n"
"E_MODEL_MARIO = 1\n"
"E_MODEL_SMOKE = 2\n"

View file

@ -75,6 +75,26 @@ void smlua_call_event_hooks(enum LuaHookedEventType hookType) {
}
}
void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value) {
lua_State* L = gLuaState;
if (L == NULL) { return; }
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
for (int i = 0; i < hook->count; i++) {
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// push value
lua_pushboolean(L, value);
// call the callback
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
smlua_logline();
continue;
}
}
}
void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m) {
lua_State* L = gLuaState;
if (L == NULL) { return; }

View file

@ -21,6 +21,7 @@ enum LuaHookedEventType {
HOOK_ON_SYNC_VALID,
HOOK_ON_OBJECT_UNLOAD,
HOOK_ON_SYNC_OBJECT_UNLOAD,
HOOK_ON_PAUSE_EXIT,
HOOK_MAX,
};
@ -41,12 +42,14 @@ static char* LuaHookedEventTypeName[] = {
"HOOK_ON_SYNC_VALID",
"HOOK_ON_OBJECT_UNLOAD",
"HOOK_ON_SYNC_OBJECT_UNLOAD",
"HOOK_ON_PAUSE_EXIT",
"HOOK_MAX"
};
extern u32 gLuaMarioActionIndex;
void smlua_call_event_hooks(enum LuaHookedEventType hookType);
void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value);
void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m);
void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2);
void smlua_call_event_hooks_mario_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2, bool* returnValue);