mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 12:05:11 +00:00
Add HOOK_BEFORE_SET_MARIO_ACTION
Param: incoming action Return: changes incoming action If the return value is 1, prevent the action from happening entirely. 0 can't be used here since it'll break the title screen.
This commit is contained in:
parent
05dd235cd0
commit
3002b0ca0f
9 changed files with 46 additions and 4 deletions
|
@ -8137,7 +8137,10 @@ HOOK_OBJECT_SET_MODEL = 28
|
|||
HOOK_CHARACTER_SOUND = 29
|
||||
|
||||
--- @type LuaHookedEventType
|
||||
HOOK_MAX = 30
|
||||
HOOK_BEFORE_SET_MARIO_ACTION = 30
|
||||
|
||||
--- @type LuaHookedEventType
|
||||
HOOK_MAX = 31
|
||||
|
||||
--- @class HudDisplayFlags
|
||||
|
||||
|
|
|
@ -748,6 +748,7 @@
|
|||
--- @field public unkC4 number
|
||||
--- @field public usedObj Object
|
||||
--- @field public vel Vec3f
|
||||
--- @field public visibleToEnemies integer
|
||||
--- @field public wall Surface
|
||||
--- @field public wallKickTimer integer
|
||||
--- @field public wallNormal Vec3f
|
||||
|
|
|
@ -2881,7 +2881,8 @@
|
|||
| HOOK_ON_CHAT_MESSAGE | 27 |
|
||||
| HOOK_OBJECT_SET_MODEL | 28 |
|
||||
| HOOK_CHARACTER_SOUND | 29 |
|
||||
| HOOK_MAX | 30 |
|
||||
| HOOK_BEFORE_SET_MARIO_ACTION | 30 |
|
||||
| HOOK_MAX | 31 |
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
|
@ -1071,6 +1071,7 @@
|
|||
| unkC4 | `number` | |
|
||||
| usedObj | [Object](structs.md#Object) | |
|
||||
| vel | [Vec3f](structs.md#Vec3f) | read-only |
|
||||
| visibleToEnemies | `integer` | |
|
||||
| wall | [Surface](structs.md#Surface) | |
|
||||
| wallKickTimer | `integer` | |
|
||||
| wallNormal | [Vec3f](structs.md#Vec3f) | read-only |
|
||||
|
|
|
@ -1093,6 +1093,10 @@ static u32 set_mario_action_cutscene(struct MarioState *m, u32 action, UNUSED u3
|
|||
* specific function if needed.
|
||||
*/
|
||||
u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg) {
|
||||
u32 returnValue = 0;
|
||||
smlua_call_event_hooks_int_param_ret_int(HOOK_BEFORE_SET_MARIO_ACTION, action, &returnValue);
|
||||
if (returnValue == 1) { return TRUE; } else if (returnValue) { action = returnValue; }
|
||||
|
||||
switch (action & ACT_GROUP_MASK) {
|
||||
case ACT_GROUP_MOVING:
|
||||
action = set_mario_action_moving(m, action, actionArg);
|
||||
|
|
|
@ -787,7 +787,7 @@ static struct LuaObjectField sMarioBodyStateFields[LUA_MARIO_BODY_STATE_FIELD_CO
|
|||
{ "wingFlutter", LVT_S8, offsetof(struct MarioBodyState, wingFlutter), false, LOT_NONE },
|
||||
};
|
||||
|
||||
#define LUA_MARIO_STATE_FIELD_COUNT 76
|
||||
#define LUA_MARIO_STATE_FIELD_COUNT 77
|
||||
static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = {
|
||||
{ "action", LVT_U32, offsetof(struct MarioState, action), false, LOT_NONE },
|
||||
{ "actionArg", LVT_U32, offsetof(struct MarioState, actionArg), false, LOT_NONE },
|
||||
|
@ -860,6 +860,7 @@ static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = {
|
|||
{ "unkC4", LVT_F32, offsetof(struct MarioState, unkC4), false, LOT_NONE },
|
||||
{ "usedObj", LVT_COBJECT_P, offsetof(struct MarioState, usedObj), false, LOT_OBJECT },
|
||||
{ "vel", LVT_COBJECT, offsetof(struct MarioState, vel), true, LOT_VEC3F },
|
||||
{ "visibleToEnemies", LVT_U8, offsetof(struct MarioState, visibleToEnemies), false, LOT_NONE },
|
||||
{ "wall", LVT_COBJECT_P, offsetof(struct MarioState, wall), false, LOT_SURFACE },
|
||||
{ "wallKickTimer", LVT_U8, offsetof(struct MarioState, wallKickTimer), false, LOT_NONE },
|
||||
{ "wallNormal", LVT_COBJECT, offsetof(struct MarioState, wallNormal), true, LOT_VEC3F },
|
||||
|
|
|
@ -2888,7 +2888,8 @@ char gSmluaConstants[] = ""
|
|||
"HOOK_ON_CHAT_MESSAGE = 27\n"
|
||||
"HOOK_OBJECT_SET_MODEL = 28\n"
|
||||
"HOOK_CHARACTER_SOUND = 29\n"
|
||||
"HOOK_MAX = 30\n"
|
||||
"HOOK_BEFORE_SET_MARIO_ACTION = 30\n"
|
||||
"HOOK_MAX = 31\n"
|
||||
"ACTION_HOOK_EVERY_FRAME = 0\n"
|
||||
"ACTION_HOOK_GRAVITY = 1\n"
|
||||
"ACTION_HOOK_MAX = 2\n"
|
||||
|
|
|
@ -671,6 +671,33 @@ bool smlua_call_event_hooks_mario_charactersound_param_ret_int(enum LuaHookedEve
|
|||
return false;
|
||||
}
|
||||
|
||||
void smlua_call_event_hooks_int_param_ret_int(enum LuaHookedEventType hookType, u32 param, u32* 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);
|
||||
|
||||
// push the callback onto the stack
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
|
||||
|
||||
// push params
|
||||
lua_pushinteger(L, param);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 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);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// hooked actions //
|
||||
////////////////////
|
||||
|
|
|
@ -41,6 +41,7 @@ enum LuaHookedEventType {
|
|||
HOOK_ON_CHAT_MESSAGE,
|
||||
HOOK_OBJECT_SET_MODEL,
|
||||
HOOK_CHARACTER_SOUND,
|
||||
HOOK_BEFORE_SET_MARIO_ACTION,
|
||||
HOOK_MAX,
|
||||
};
|
||||
|
||||
|
@ -75,6 +76,7 @@ static const char* LuaHookedEventTypeName[] = {
|
|||
"HOOK_ON_CHAT_MESSAGE",
|
||||
"HOOK_OBJECT_SET_MODEL",
|
||||
"HOOK_CHARACTER_SOUND",
|
||||
"HOOK_BEFORE_SET_MARIO_ACTION",
|
||||
"HOOK_MAX"
|
||||
};
|
||||
|
||||
|
@ -113,6 +115,7 @@ void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int
|
|||
void smlua_call_event_hooks_ret_bool(enum LuaHookedEventType hookType, bool* returnValue);
|
||||
void smlua_call_event_hooks_on_chat_message(enum LuaHookedEventType hookType, struct MarioState* m, const char* message, bool* returnValue);
|
||||
bool smlua_call_event_hooks_mario_charactersound_param_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, enum CharacterSound characterSound, s32* returnValue);
|
||||
void smlua_call_event_hooks_int_param_ret_int(enum LuaHookedEventType hookType, u32 param, u32* returnValue);
|
||||
|
||||
enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior);
|
||||
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);
|
||||
|
|
Loading…
Reference in a new issue