From 7252d836a9cc8e7221ffbd61b3e34296d66fa627 Mon Sep 17 00:00:00 2001 From: MysterD Date: Wed, 16 Mar 2022 23:53:01 -0700 Subject: [PATCH] Added hooks: HOOK_ON_LEVEL_INIT, HOOK_ON_WARP, HOOK_ON_SYNC_VALID --- autogen/lua_definitions/constants.lua | 11 ++++++++++- docs/lua/constants.md | 5 ++++- docs/lua/hooks.md | 3 +++ src/game/level_update.c | 4 ++++ src/pc/lua/smlua_constants_autogen.c | 5 ++++- src/pc/lua/smlua_hooks.h | 6 ++++++ src/pc/network/packets/packet_sync_valid.c | 9 +++++++++ 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index cc6972e18..678ab4356 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -5282,7 +5282,16 @@ HOOK_ON_HUD_RENDER = 9 HOOK_ON_INTERACT = 10 --- @type LuaHookedEventType -HOOK_MAX = 11 +HOOK_ON_LEVEL_INIT = 11 + +--- @type LuaHookedEventType +HOOK_ON_WARP = 12 + +--- @type LuaHookedEventType +HOOK_ON_SYNC_VALID = 13 + +--- @type LuaHookedEventType +HOOK_MAX = 14 --- @class ModelExtendedId diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 49f4494f9..560dd4963 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -1858,7 +1858,10 @@ | HOOK_ON_PLAYER_DISCONNECTED | 8 | | HOOK_ON_HUD_RENDER | 9 | | HOOK_ON_INTERACT | 10 | -| HOOK_MAX | 11 | +| HOOK_ON_LEVEL_INIT | 11 | +| HOOK_ON_WARP | 12 | +| HOOK_ON_SYNC_VALID | 13 | +| HOOK_MAX | 14 | [:arrow_up_small:](#) diff --git a/docs/lua/hooks.md b/docs/lua/hooks.md index 4b102665f..cb5ebb727 100644 --- a/docs/lua/hooks.md +++ b/docs/lua/hooks.md @@ -97,6 +97,9 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_PLAYER_DISCONNECTED | Called when a player disconnects | [MarioState](structs.md#MarioState) disconnector | | HOOK_ON_HUD_RENDER | Called when the HUD is being rendered | None | | HOOK_ON_INTERACT | Called when mario interacts with an object | [MarioState](structs.md#MarioState) interactor, [Object](structs.md#Object) interactee, [enum InteractionType](constants.md#enum-InteractionType) interactType, bool interactValue | +| HOOK_ON_LEVEL_INIT | Called when the level is initialized | None | +| HOOK_ON_WARP | Called when the local player warps | None | +| HOOK_ON_SYNC_VALID | Called when the current area is synchronized | None | ### Parameters diff --git a/src/game/level_update.c b/src/game/level_update.c index 94c3bdc91..28ae39a6d 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -36,6 +36,7 @@ #include "pc/configfile.h" #include "pc/network/network.h" #include "pc/djui/djui.h" +#include "pc/lua/smlua_hooks.h" #include "game/screen_transition.h" @@ -521,6 +522,7 @@ void init_mario_after_warp(void) { } #endif } + smlua_call_event_hooks(HOOK_ON_WARP); } // used for warps inside one level @@ -1413,6 +1415,8 @@ s32 init_level(void) { sound_banks_disable(SEQ_PLAYER_SFX, SOUND_BANKS_DISABLED_DURING_INTRO_CUTSCENE); } + smlua_call_event_hooks(HOOK_ON_LEVEL_INIT); + return 1; } diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 84a6badc3..a43e91211 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -1900,7 +1900,10 @@ char gSmluaConstants[] = "" "HOOK_ON_PLAYER_DISCONNECTED = 8\n" "HOOK_ON_HUD_RENDER = 9\n" "HOOK_ON_INTERACT = 10\n" -"HOOK_MAX = 11\n" +"HOOK_ON_LEVEL_INIT = 11\n" +"HOOK_ON_WARP = 12\n" +"HOOK_ON_SYNC_VALID = 13\n" +"HOOK_MAX = 14\n" "E_MODEL_NONE = 0\n" "E_MODEL_MARIO = 1\n" "E_MODEL_SMOKE = 2\n" diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index e5d4c77e8..987be4423 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -16,6 +16,9 @@ enum LuaHookedEventType { HOOK_ON_PLAYER_DISCONNECTED, HOOK_ON_HUD_RENDER, HOOK_ON_INTERACT, + HOOK_ON_LEVEL_INIT, + HOOK_ON_WARP, + HOOK_ON_SYNC_VALID, HOOK_MAX, }; @@ -31,6 +34,9 @@ static char* LuaHookedEventTypeName[] = { "HOOK_ON_PLAYER_DISCONNECTED", "HOOK_ON_HUD_RENDER", "HOOK_ON_INTERACT", + "HOOK_ON_LEVEL_INIT", + "HOOK_ON_WARP", + "HOOK_ON_SYNC_VALID", "HOOK_MAX" }; diff --git a/src/pc/network/packets/packet_sync_valid.c b/src/pc/network/packets/packet_sync_valid.c index 1a0446b64..677299659 100644 --- a/src/pc/network/packets/packet_sync_valid.c +++ b/src/pc/network/packets/packet_sync_valid.c @@ -1,9 +1,14 @@ #include #include "../network.h" +#include "pc/lua/smlua_hooks.h" //#define DISABLE_MODULE_LOG 1 #include "pc/debuglog.h" void network_send_sync_valid(struct NetworkPlayer* toNp, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) { + if (toNp == gNetworkPlayerLocal && !toNp->currAreaSyncValid) { + smlua_call_event_hooks(HOOK_ON_SYNC_VALID); + } + // set the NetworkPlayers sync valid toNp->currLevelSyncValid = true; toNp->currAreaSyncValid = true; @@ -55,6 +60,10 @@ void network_receive_sync_valid(struct Packet* p) { return; } + if (np == gNetworkPlayerLocal && !np->currAreaSyncValid) { + smlua_call_event_hooks(HOOK_ON_SYNC_VALID); + } + np->currLevelSyncValid = true; np->currAreaSyncValid = true;