Added HOOK_GET_STAR_COLLECTION_DIALOG

This commit is contained in:
MysterD 2022-04-10 02:44:11 -07:00
parent 958b04378c
commit 957e03cd81
7 changed files with 43 additions and 3 deletions

View file

@ -7721,7 +7721,10 @@ HOOK_ON_SYNC_OBJECT_UNLOAD = 15
HOOK_ON_PAUSE_EXIT = 16 HOOK_ON_PAUSE_EXIT = 16
--- @type LuaHookedEventType --- @type LuaHookedEventType
HOOK_MAX = 17 HOOK_GET_STAR_COLLECTION_DIALOG = 17
--- @type LuaHookedEventType
HOOK_MAX = 18
--- @class ModelExtendedId --- @class ModelExtendedId

View file

@ -2700,7 +2700,8 @@
| HOOK_ON_OBJECT_UNLOAD | 14 | | HOOK_ON_OBJECT_UNLOAD | 14 |
| HOOK_ON_SYNC_OBJECT_UNLOAD | 15 | | HOOK_ON_SYNC_OBJECT_UNLOAD | 15 |
| HOOK_ON_PAUSE_EXIT | 16 | | HOOK_ON_PAUSE_EXIT | 16 |
| HOOK_MAX | 17 | | HOOK_GET_STAR_COLLECTION_DIALOG | 17 |
| HOOK_MAX | 18 |
[:arrow_up_small:](#) [:arrow_up_small:](#)

View file

@ -103,6 +103,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| HOOK_ON_OBJECT_UNLOAD | Called when any object is unloaded | [Object](structs.md#Object) unloadedObject | | 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_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, return `false` to prevent the exit | `boolean` usedExitToCastle | | HOOK_ON_PAUSE_EXIT | Called when the local player exits through the pause screen, return `false` to prevent the exit | `boolean` usedExitToCastle |
| HOOK_GET_STAR_COLLECTION_DIALOG | Called when the local player collects a star, return a [DialogId](constants.md#enum-DialogId) to show a message | None |
### Parameters ### Parameters

View file

@ -241,6 +241,10 @@ static void stub_is_textbox_active(u16 *a0) {
s32 get_star_collection_dialog(struct MarioState *m) { s32 get_star_collection_dialog(struct MarioState *m) {
s32 dialogID = 0; s32 dialogID = 0;
if (smlua_call_event_hooks_ret_int(HOOK_GET_STAR_COLLECTION_DIALOG, &dialogID)) {
return dialogID;
}
for (s32 i = 0; i < ARRAY_COUNT(sStarsNeededForDialog); i++) { for (s32 i = 0; i < ARRAY_COUNT(sStarsNeededForDialog); i++) {
s32 numStarsRequired = sStarsNeededForDialog[i]; s32 numStarsRequired = sStarsNeededForDialog[i];
if (m->prevNumStarsForDialog < numStarsRequired && m->numStars >= numStarsRequired) { if (m->prevNumStarsForDialog < numStarsRequired && m->numStars >= numStarsRequired) {

View file

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

View file

@ -264,6 +264,33 @@ void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struc
} }
} }
bool smlua_call_event_hooks_ret_int(enum LuaHookedEventType hookType, s32* returnValue) {
lua_State* L = gLuaState;
if (L == NULL) { return false; }
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
for (int i = 0; i < hook->count; i++) {
s32 prevTop = lua_gettop(L);
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// call the callback
if (0 != smlua_call_hook(L, 0, 1, 0, hook->mod[i])) {
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
smlua_logline();
continue;
}
// output the return value
if (lua_type(L, -1) == LUA_TNUMBER) {
*returnValue = smlua_to_integer(L, -1);
}
lua_settop(L, prevTop);
return true;
}
return false;
}
void smlua_call_event_hooks_network_player_param(enum LuaHookedEventType hookType, struct NetworkPlayer* np) { void smlua_call_event_hooks_network_player_param(enum LuaHookedEventType hookType, struct NetworkPlayer* np) {
lua_State* L = gLuaState; lua_State* L = gLuaState;
if (L == NULL) { return; } if (L == NULL) { return; }

View file

@ -22,6 +22,7 @@ enum LuaHookedEventType {
HOOK_ON_OBJECT_UNLOAD, HOOK_ON_OBJECT_UNLOAD,
HOOK_ON_SYNC_OBJECT_UNLOAD, HOOK_ON_SYNC_OBJECT_UNLOAD,
HOOK_ON_PAUSE_EXIT, HOOK_ON_PAUSE_EXIT,
HOOK_GET_STAR_COLLECTION_DIALOG,
HOOK_MAX, HOOK_MAX,
}; };
@ -43,6 +44,7 @@ static char* LuaHookedEventTypeName[] = {
"HOOK_ON_OBJECT_UNLOAD", "HOOK_ON_OBJECT_UNLOAD",
"HOOK_ON_SYNC_OBJECT_UNLOAD", "HOOK_ON_SYNC_OBJECT_UNLOAD",
"HOOK_ON_PAUSE_EXIT", "HOOK_ON_PAUSE_EXIT",
"HOOK_GET_STAR_COLLECTION_DIALOG",
"HOOK_MAX" "HOOK_MAX"
}; };
@ -56,6 +58,7 @@ void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struc
void smlua_call_event_hooks_mario_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2, bool* returnValue); void smlua_call_event_hooks_mario_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2, bool* returnValue);
void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool interactValue); void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool interactValue);
void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struct Object* obj); void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struct Object* obj);
bool smlua_call_event_hooks_ret_int(enum LuaHookedEventType hookType, s32* returnValue);
enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior); enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior);
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior); const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);