mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-25 05:25:14 +00:00
added HOOK_ON_SEQ_LOAD (#18)
This commit is contained in:
parent
15377ada33
commit
a7b2741aa7
6 changed files with 48 additions and 3 deletions
|
@ -9324,7 +9324,10 @@ HOOK_ON_OBJECT_LOAD = 40
|
||||||
HOOK_ON_PLAY_SOUND = 41
|
HOOK_ON_PLAY_SOUND = 41
|
||||||
|
|
||||||
--- @type LuaHookedEventType
|
--- @type LuaHookedEventType
|
||||||
HOOK_MAX = 42
|
HOOK_ON_SEQ_LOAD = 42
|
||||||
|
|
||||||
|
--- @type LuaHookedEventType
|
||||||
|
HOOK_MAX = 43
|
||||||
|
|
||||||
--- @class HudDisplayFlags
|
--- @class HudDisplayFlags
|
||||||
|
|
||||||
|
|
|
@ -3332,7 +3332,8 @@
|
||||||
| HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED | 39 |
|
| HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED | 39 |
|
||||||
| HOOK_ON_OBJECT_LOAD | 40 |
|
| HOOK_ON_OBJECT_LOAD | 40 |
|
||||||
| HOOK_ON_PLAY_SOUND | 41 |
|
| HOOK_ON_PLAY_SOUND | 41 |
|
||||||
| HOOK_MAX | 42 |
|
| HOOK_ON_SEQ_LOAD | 42 |
|
||||||
|
| HOOK_MAX | 43 |
|
||||||
|
|
||||||
[:arrow_up_small:](#)
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "pc/platform.h"
|
#include "pc/platform.h"
|
||||||
#include "pc/fs/fs.h"
|
#include "pc/fs/fs.h"
|
||||||
#include "pc/lua/utils/smlua_audio_utils.h"
|
#include "pc/lua/utils/smlua_audio_utils.h"
|
||||||
|
#include "pc/lua/smlua_hooks.h"
|
||||||
|
|
||||||
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
|
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
|
||||||
|
|
||||||
|
@ -1552,6 +1553,13 @@ void preload_sequence(u32 seqId, u8 preloadMask) {
|
||||||
void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync);
|
void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync);
|
||||||
|
|
||||||
void load_sequence(u32 player, u32 seqId, s32 loadAsync) {
|
void load_sequence(u32 player, u32 seqId, s32 loadAsync) {
|
||||||
|
u8 returnValue = 0;
|
||||||
|
|
||||||
|
smlua_call_event_hooks_on_seq_load(HOOK_ON_SEQ_LOAD, player, seqId, loadAsync, &returnValue);
|
||||||
|
if (returnValue != 0) {
|
||||||
|
seqId = returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!loadAsync) {
|
if (!loadAsync) {
|
||||||
gAudioLoadLock = AUDIO_LOCK_LOADING;
|
gAudioLoadLock = AUDIO_LOCK_LOADING;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3307,7 +3307,8 @@ char gSmluaConstants[] = ""
|
||||||
"HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED = 39\n"
|
"HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED = 39\n"
|
||||||
"HOOK_ON_OBJECT_LOAD = 40\n"
|
"HOOK_ON_OBJECT_LOAD = 40\n"
|
||||||
"HOOK_ON_PLAY_SOUND = 41\n"
|
"HOOK_ON_PLAY_SOUND = 41\n"
|
||||||
"HOOK_MAX = 42\n"
|
"HOOK_ON_SEQ_LOAD = 42\n"
|
||||||
|
"HOOK_MAX = 43\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"
|
||||||
|
|
|
@ -727,6 +727,35 @@ void smlua_call_event_hooks_on_play_sound(enum LuaHookedEventType hookType, s32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void smlua_call_event_hooks_on_seq_load(enum LuaHookedEventType hookType, u32 player, u32 seqId, s32 loadAsync, u8* returnValue) {
|
||||||
|
lua_State* L = gLuaState;
|
||||||
|
if (L == NULL) { return; }
|
||||||
|
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
|
||||||
|
for (int i = 0; i < hook->count; i++) {
|
||||||
|
s32 prevTop = lua_gettop(L);
|
||||||
|
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
|
||||||
|
lua_pushinteger(L, player);
|
||||||
|
lua_pushinteger(L, seqId);
|
||||||
|
lua_pushinteger(L, loadAsync);
|
||||||
|
|
||||||
|
// Call the callback
|
||||||
|
if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) {
|
||||||
|
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output the return value
|
||||||
|
if (lua_type(L, -1) == LUA_TNUMBER) {
|
||||||
|
*returnValue = smlua_to_integer(L, -1);
|
||||||
|
lua_settop(L, prevTop);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
lua_settop(L, prevTop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
lua_State* L = gLuaState;
|
lua_State* L = gLuaState;
|
||||||
*foundHook = false;
|
*foundHook = false;
|
||||||
|
|
|
@ -53,6 +53,7 @@ enum LuaHookedEventType {
|
||||||
HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED,
|
HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED,
|
||||||
HOOK_ON_OBJECT_LOAD,
|
HOOK_ON_OBJECT_LOAD,
|
||||||
HOOK_ON_PLAY_SOUND,
|
HOOK_ON_PLAY_SOUND,
|
||||||
|
HOOK_ON_SEQ_LOAD,
|
||||||
HOOK_MAX,
|
HOOK_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -99,6 +100,7 @@ static const char* LuaHookedEventTypeName[] = {
|
||||||
"HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED",
|
"HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED",
|
||||||
"HOOK_ON_OBJECT_LOAD",
|
"HOOK_ON_OBJECT_LOAD",
|
||||||
"HOOK_ON_PLAY_SOUND",
|
"HOOK_ON_PLAY_SOUND",
|
||||||
|
"HOOK_ON_SEQ_LOAD",
|
||||||
"HOOK_MAX"
|
"HOOK_MAX"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -147,6 +149,7 @@ bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType
|
||||||
bool smlua_call_event_hooks_mario_param_ret_float(enum LuaHookedEventType hookType, struct MarioState* m, f32* returnValue);
|
bool smlua_call_event_hooks_mario_param_ret_float(enum LuaHookedEventType hookType, struct MarioState* m, f32* returnValue);
|
||||||
bool smlua_call_event_hooks_mario_param_and_int_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, u32 args, s32* returnValue);
|
bool smlua_call_event_hooks_mario_param_and_int_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, u32 args, s32* returnValue);
|
||||||
void smlua_call_event_hooks_graph_node_object_and_int_param(enum LuaHookedEventType hookType, struct GraphNodeObject* node, s32 param);
|
void smlua_call_event_hooks_graph_node_object_and_int_param(enum LuaHookedEventType hookType, struct GraphNodeObject* node, s32 param);
|
||||||
|
void smlua_call_event_hooks_on_seq_load(enum LuaHookedEventType hookType, u32 player, u32 seqId, s32 loadAsync, u8* 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);
|
||||||
|
|
Loading…
Reference in a new issue