HOOK_ON_SCREEN_TRANSITION (#192)

This commit is contained in:
Agent X 2022-09-18 20:30:29 -04:00 committed by GitHub
parent 6449b7d578
commit f726fb5d74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 8 deletions

View file

@ -7940,7 +7940,10 @@ HOOK_USE_ACT_SELECT = 23
HOOK_ON_CHANGE_CAMERA_ANGLE = 24 HOOK_ON_CHANGE_CAMERA_ANGLE = 24
--- @type LuaHookedEventType --- @type LuaHookedEventType
HOOK_MAX = 25 HOOK_ON_SCREEN_TRANSITION = 25
--- @type LuaHookedEventType
HOOK_MAX = 26
--- @class HudDisplayFlags --- @class HudDisplayFlags

View file

@ -2807,7 +2807,8 @@
| HOOK_ON_PACKET_RECEIVE | 22 | | HOOK_ON_PACKET_RECEIVE | 22 |
| HOOK_USE_ACT_SELECT | 23 | | HOOK_USE_ACT_SELECT | 23 |
| HOOK_ON_CHANGE_CAMERA_ANGLE | 24 | | HOOK_ON_CHANGE_CAMERA_ANGLE | 24 |
| HOOK_MAX | 25 | | HOOK_ON_SCREEN_TRANSITION | 25 |
| HOOK_MAX | 26 |
[:arrow_up_small:](#) [:arrow_up_small:](#)

View file

@ -111,6 +111,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| HOOK_ON_PACKET_RECEIVE | Called when the mod receives a packet that used `network_send()` or `network_send_to()` | `table` dataTable | | HOOK_ON_PACKET_RECEIVE | Called when the mod receives a packet that used `network_send()` or `network_send_to()` | `table` dataTable |
| HOOK_USE_ACT_SELECT | Called when the level changes, return `true` to show act selection screen and `false` otherwise | `integer` levelNum | | HOOK_USE_ACT_SELECT | Called when the level changes, return `true` to show act selection screen and `false` otherwise | `integer` levelNum |
| HOOK_ON_CHANGE_CAMERA_ANGLE | Called when the player changes the camera mode to Lakitu cam or Mario cam, return `false` to prevent the change. | `integer` mode | | HOOK_ON_CHANGE_CAMERA_ANGLE | Called when the player changes the camera mode to Lakitu cam or Mario cam, return `false` to prevent the change. | `integer` mode |
| HOOK_ON_SCREEN_TRANSITION | Called when the game is about to play a transition, returun `false` to prevent the transition from playing. | `integer` type |
### Parameters ### Parameters

View file

@ -24,6 +24,7 @@
#include "gfx_dimensions.h" #include "gfx_dimensions.h"
#include "game/ingame_menu.h" #include "game/ingame_menu.h"
#include "pc/network/network.h" #include "pc/network/network.h"
#include "pc/lua/smlua_hooks.h"
struct SpawnInfo gPlayerSpawnInfos[MAX_PLAYERS]; struct SpawnInfo gPlayerSpawnInfos[MAX_PLAYERS];
struct GraphNode *D_8033A160[MAX_LOADED_GRAPH_NODES]; struct GraphNode *D_8033A160[MAX_LOADED_GRAPH_NODES];
@ -341,6 +342,10 @@ void area_update_objects(void) {
* transition type, time in frames, and the RGB color that will fill the screen. * transition type, time in frames, and the RGB color that will fill the screen.
*/ */
void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue) { void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue) {
bool returnValue = true;
smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_SCREEN_TRANSITION, transType, &returnValue);
if (!returnValue) { return; }
gWarpTransition.isActive = TRUE; gWarpTransition.isActive = TRUE;
gWarpTransition.type = transType; gWarpTransition.type = transType;
gWarpTransition.time = time; gWarpTransition.time = time;

View file

@ -3068,12 +3068,12 @@ void update_camera(struct Camera *c) {
if ((sCurrPlayMode != PLAY_MODE_PAUSED) && gPlayer1Controller->buttonPressed & R_TRIG) { if ((sCurrPlayMode != PLAY_MODE_PAUSED) && gPlayer1Controller->buttonPressed & R_TRIG) {
bool returnValue = true; bool returnValue = true;
if (set_cam_angle(0) == CAM_ANGLE_LAKITU) { if (set_cam_angle(0) == CAM_ANGLE_LAKITU) {
smlua_call_event_hooks_change_camera_angle_params(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_MARIO, &returnValue); smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_MARIO, &returnValue);
if (returnValue) { if (returnValue) {
set_cam_angle(CAM_ANGLE_MARIO); set_cam_angle(CAM_ANGLE_MARIO);
} }
} else { } else {
smlua_call_event_hooks_change_camera_angle_params(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_LAKITU, &returnValue); smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_LAKITU, &returnValue);
if (returnValue) { if (returnValue) {
set_cam_angle(CAM_ANGLE_LAKITU); set_cam_angle(CAM_ANGLE_LAKITU);
} }

View file

@ -2826,7 +2826,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_PACKET_RECEIVE = 22\n" "HOOK_ON_PACKET_RECEIVE = 22\n"
"HOOK_USE_ACT_SELECT = 23\n" "HOOK_USE_ACT_SELECT = 23\n"
"HOOK_ON_CHANGE_CAMERA_ANGLE = 24\n" "HOOK_ON_CHANGE_CAMERA_ANGLE = 24\n"
"HOOK_MAX = 25\n" "HOOK_ON_SCREEN_TRANSITION = 25\n"
"HOOK_MAX = 26\n"
"ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_EVERY_FRAME = 0\n"
"ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_GRAVITY = 1\n"
"ACTION_HOOK_MAX = 2\n" "ACTION_HOOK_MAX = 2\n"

View file

@ -477,7 +477,7 @@ void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookT
} }
} }
void smlua_call_event_hooks_change_camera_angle_params(enum LuaHookedEventType hookType, s16 mode, bool* returnValue) { void smlua_call_event_hooks_int_params_ret_bool(enum LuaHookedEventType hookType, s16 param, bool* returnValue) {
lua_State* L = gLuaState; lua_State* L = gLuaState;
if (L == NULL) { return; } if (L == NULL) { return; }
*returnValue = true; *returnValue = true;
@ -490,7 +490,7 @@ void smlua_call_event_hooks_change_camera_angle_params(enum LuaHookedEventType h
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// push params // push params
lua_pushinteger(L, mode); lua_pushinteger(L, param);
// call the callback // call the callback
if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) {

View file

@ -36,6 +36,7 @@ enum LuaHookedEventType {
HOOK_ON_PACKET_RECEIVE, HOOK_ON_PACKET_RECEIVE,
HOOK_USE_ACT_SELECT, HOOK_USE_ACT_SELECT,
HOOK_ON_CHANGE_CAMERA_ANGLE, HOOK_ON_CHANGE_CAMERA_ANGLE,
HOOK_ON_SCREEN_TRANSITION,
HOOK_MAX, HOOK_MAX,
}; };
@ -65,6 +66,7 @@ static const char* LuaHookedEventTypeName[] = {
"HOOK_ON_PACKET_RECEIVE", "HOOK_ON_PACKET_RECEIVE",
"HOOK_USE_ACT_SELECT", "HOOK_USE_ACT_SELECT",
"HOOK_ON_CHANGE_CAMERA_ANGLE", "HOOK_ON_CHANGE_CAMERA_ANGLE",
"HOOK_ON_SCREEN_TRANSITION",
"HOOK_MAX" "HOOK_MAX"
}; };
@ -96,7 +98,7 @@ void smlua_call_event_hooks_interact_params_ret_bool(enum LuaHookedEventType hoo
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); bool smlua_call_event_hooks_ret_int(enum LuaHookedEventType hookType, s32* returnValue);
void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookType, struct Camera *c, s16 mode, s16 frames, bool* returnValue); void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookType, struct Camera *c, s16 mode, s16 frames, bool* returnValue);
void smlua_call_event_hooks_change_camera_angle_params(enum LuaHookedEventType hookType, s16 mode, bool* returnValue); void smlua_call_event_hooks_int_params_ret_bool(enum LuaHookedEventType hookType, s16 param, bool* returnValue);
void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int modIndex, int valueIndex); void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int modIndex, int valueIndex);
void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue); void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue);