From 0cd2a91e9c60d872592c4ca6f32a2c49000bc9d4 Mon Sep 17 00:00:00 2001 From: MysterD Date: Thu, 17 Mar 2022 01:17:34 -0700 Subject: [PATCH] Added allocate_mario_action() --- autogen/lua_definitions/constants.lua | 3 +++ autogen/lua_definitions/functions.lua | 6 ++++++ docs/lua/constants.md | 1 + docs/lua/functions.md | 21 +++++++++++++++++++++ include/sm64.h | 1 + mods/character-movesets.lua | 14 +++++++------- mods/extended-moveset.lua | 24 ++++++++++++------------ src/pc/lua/smlua_constants_autogen.c | 1 + src/pc/lua/smlua_functions_autogen.c | 12 ++++++++++++ src/pc/lua/smlua_hooks.c | 2 ++ src/pc/lua/smlua_hooks.h | 2 ++ src/pc/lua/utils/smlua_misc_utils.c | 6 ++++++ src/pc/lua/utils/smlua_misc_utils.h | 2 ++ 13 files changed, 76 insertions(+), 19 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 678ab435..3913bc7f 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -4385,6 +4385,9 @@ ACT_FLAG_BUTT_OR_STOMACH_SLIDE = (1 << 18) --- @type integer ACT_FLAG_CONTROL_JUMP_HEIGHT = (1 << 25) +--- @type integer +ACT_FLAG_CUSTOM_ACTION = (1 << 30) + --- @type integer ACT_FLAG_DIVING = (1 << 19) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index a45ac4c8..b318d282 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -3476,6 +3476,12 @@ function collision_find_surface_on_ray(startX, startY, startZ, endX, endY, endZ) -- ... end +--- @param actFlags integer +--- @return integer +function allocate_mario_action(actFlags) + -- ... +end + --- @return integer function get_network_area_timer() -- ... diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 560dd496..3dcb4592 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -1550,6 +1550,7 @@ - ACT_FLAG_ATTACKING - ACT_FLAG_BUTT_OR_STOMACH_SLIDE - ACT_FLAG_CONTROL_JUMP_HEIGHT +- ACT_FLAG_CUSTOM_ACTION - ACT_FLAG_DIVING - ACT_FLAG_HANGING - ACT_FLAG_IDLE diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 5296ab61..6c550dd2 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -634,6 +634,7 @@
- smlua_misc_utils.h + - [allocate_mario_action](#allocate_mario_action) - [get_network_area_timer](#get_network_area_timer) - [hud_hide](#hud_hide) - [hud_show](#hud_show) @@ -11614,6 +11615,26 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [allocate_mario_action](#allocate_mario_action) + +### Lua Example +`local integerValue = allocate_mario_action(actFlags)` + +### Parameters +| Field | Type | +| ----- | ---- | +| actFlags | `integer` | + +### Returns +- `integer` + +### C Prototype +`u32 allocate_mario_action(u32 actFlags);` + +[:arrow_up_small:](#) + +
+ ## [get_network_area_timer](#get_network_area_timer) ### Lua Example diff --git a/include/sm64.h b/include/sm64.h index b3f1ed34..e31e3eda 100644 --- a/include/sm64.h +++ b/include/sm64.h @@ -167,6 +167,7 @@ #define ACT_FLAG_PAUSE_EXIT /* 0x08000000 */ (1 << 27) #define ACT_FLAG_SWIMMING_OR_FLYING /* 0x10000000 */ (1 << 28) #define ACT_FLAG_WATER_OR_TEXT /* 0x20000000 */ (1 << 29) +#define ACT_FLAG_CUSTOM_ACTION /* 0x40000000 */ (1 << 30) #define ACT_FLAG_THROWING /* 0x80000000 */ (1 << 31) #define ACT_UNINITIALIZED 0x00000000 // (0x000) diff --git a/mods/character-movesets.lua b/mods/character-movesets.lua index 3339976c..515e2b9d 100644 --- a/mods/character-movesets.lua +++ b/mods/character-movesets.lua @@ -36,8 +36,8 @@ end -- luigi -- ----------- -ACT_SPIN_POUND_LAND = (0x037 | ACT_FLAG_STATIONARY | ACT_FLAG_ATTACKING) -ACT_SPIN_POUND = (0x08F | ACT_FLAG_AIR | ACT_FLAG_ATTACKING) +ACT_SPIN_POUND_LAND = allocate_mario_action(ACT_FLAG_STATIONARY | ACT_FLAG_ATTACKING) +ACT_SPIN_POUND = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_ATTACKING) function act_spin_pound(m) local e = gStateExtras[m.playerIndex] @@ -360,7 +360,7 @@ gEventTable[CT_TOAD] = { -- waluigi -- ------------- -ACT_WALL_SLIDE = (0x0BF | ACT_FLAG_AIR | ACT_FLAG_MOVING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) +ACT_WALL_SLIDE = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_MOVING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) function act_wall_slide(m) if (m.input & INPUT_A_PRESSED) ~= 0 then @@ -482,10 +482,10 @@ gEventTable[CT_WALUIGI] = { -- wario -- ----------- -ACT_WARIO_DASH = (0x05B | ACT_FLAG_MOVING | ACT_FLAG_ATTACKING) -ACT_WARIO_AIR_DASH = (0x05B | ACT_FLAG_AIR | ACT_FLAG_ATTACKING) -ACT_CORKSCREW_CONK = (0x05D | ACT_FLAG_AIR | ACT_FLAG_ATTACKING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) -ACT_WARIO_SPINNING_OBJ = (0x05B | ACT_FLAG_STATIONARY) +ACT_WARIO_DASH = allocate_mario_action(ACT_FLAG_MOVING | ACT_FLAG_ATTACKING) +ACT_WARIO_AIR_DASH = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_ATTACKING) +ACT_CORKSCREW_CONK = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_ATTACKING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) +ACT_WARIO_SPINNING_OBJ = allocate_mario_action(ACT_FLAG_STATIONARY) function act_corkscrew_conk(m) local e = gStateExtras[m.playerIndex] diff --git a/mods/extended-moveset.lua b/mods/extended-moveset.lua index c9777e1a..b3b5f02e 100644 --- a/mods/extended-moveset.lua +++ b/mods/extended-moveset.lua @@ -6,18 +6,18 @@ -- initialize actions -- ------------------------ -ACT_SPIN_POUND_LAND = (0x037 | ACT_FLAG_STATIONARY | ACT_FLAG_ATTACKING) -ACT_ROLL = (0x05B | ACT_FLAG_MOVING | ACT_FLAG_BUTT_OR_STOMACH_SLIDE) -ACT_GROUND_POUND_JUMP = (0x084 | ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) -ACT_SPIN_JUMP = (0x08B | ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) -ACT_SPIN_POUND = (0x08F | ACT_FLAG_AIR | ACT_FLAG_ATTACKING) -ACT_LEDGE_PARKOUR = (0x09D | ACT_FLAG_AIR) -ACT_ROLL_AIR = (0x0BA | ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) -ACT_WALL_SLIDE = (0x0BF | ACT_FLAG_AIR | ACT_FLAG_MOVING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) -ACT_WATER_GROUND_POUND = (0x0C9 | ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT | ACT_FLAG_ATTACKING) -ACT_WATER_GROUND_POUND_LAND = (0x0CA | ACT_FLAG_STATIONARY | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT) -ACT_WATER_GROUND_POUND_STROKE = (0x0CB | ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT) -ACT_WATER_GROUND_POUND_JUMP = (0x0CC | ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT) +ACT_SPIN_POUND_LAND = allocate_mario_action(ACT_FLAG_STATIONARY | ACT_FLAG_ATTACKING) +ACT_ROLL = allocate_mario_action(ACT_FLAG_MOVING | ACT_FLAG_BUTT_OR_STOMACH_SLIDE) +ACT_GROUND_POUND_JUMP = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) +ACT_SPIN_JUMP = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) +ACT_SPIN_POUND = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_ATTACKING) +ACT_LEDGE_PARKOUR = allocate_mario_action(ACT_FLAG_AIR) +ACT_ROLL_AIR = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) +ACT_WALL_SLIDE = allocate_mario_action(ACT_FLAG_AIR | ACT_FLAG_MOVING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION) +ACT_WATER_GROUND_POUND = allocate_mario_action(ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT | ACT_FLAG_ATTACKING) +ACT_WATER_GROUND_POUND_LAND = allocate_mario_action(ACT_FLAG_STATIONARY | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT) +ACT_WATER_GROUND_POUND_STROKE = allocate_mario_action(ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT) +ACT_WATER_GROUND_POUND_JUMP = allocate_mario_action(ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT) ----------------------------- -- initialize extra fields -- diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index a43e9121..ea73d035 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -1651,6 +1651,7 @@ char gSmluaConstants[] = "" "ACT_FLAG_PAUSE_EXIT = (1 << 27)\n" "ACT_FLAG_SWIMMING_OR_FLYING = (1 << 28)\n" "ACT_FLAG_WATER_OR_TEXT = (1 << 29)\n" +"ACT_FLAG_CUSTOM_ACTION = (1 << 30)\n" "ACT_FLAG_THROWING = (1 << 31)\n" "ACT_UNINITIALIZED = 0x00000000\n" "ACT_IDLE = 0x0C400201\n" diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 3ef69dcf..f7021451 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -7400,6 +7400,17 @@ int smlua_func_collision_find_surface_on_ray(lua_State* L) { // smlua_misc_utils.h // //////////////////////// +int smlua_func_allocate_mario_action(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 1)) { return 0; } + + u32 actFlags = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { return 0; } + + lua_pushinteger(L, allocate_mario_action(actFlags)); + + return 1; +} + int smlua_func_get_network_area_timer(UNUSED lua_State* L) { if(!smlua_functions_valid_param_count(L, 0)) { return 0; } @@ -8769,6 +8780,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "collision_find_surface_on_ray", smlua_func_collision_find_surface_on_ray); // smlua_misc_utils.h + smlua_bind_function(L, "allocate_mario_action", smlua_func_allocate_mario_action); smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer); smlua_bind_function(L, "hud_hide", smlua_func_hud_hide); smlua_bind_function(L, "hud_show", smlua_func_hud_show); diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 296d8b35..4507cecb 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -230,6 +230,7 @@ struct LuaHookedMarioAction { static struct LuaHookedMarioAction sHookedMarioActions[MAX_HOOKED_ACTIONS] = { 0 }; static int sHookedMarioActionsCount = 0; +u32 gLuaMarioActionIndex = 0; int smlua_hook_mario_action(lua_State* L) { if (L == NULL) { return 0; } @@ -742,6 +743,7 @@ static void smlua_clear_hooks(void) { hooked->mod = NULL; } sHookedBehaviorsCount = 0; + gLuaMarioActionIndex = 0; } void smlua_bind_hooks(void) { diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 987be442..e81eede4 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -40,6 +40,8 @@ static char* LuaHookedEventTypeName[] = { "HOOK_MAX" }; +extern u32 gLuaMarioActionIndex; + void smlua_call_event_hooks(enum LuaHookedEventType hookType); void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m); void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index 9f4d0826..0b786268 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -1,3 +1,4 @@ +#include "sm64.h" #include "types.h" #include "data/dynos_coop.c.h" @@ -33,3 +34,8 @@ bool warp_exit_level(s32 aDelay) { bool warp_to_castle(s32 aLevel) { return dynos_warp_to_castle(aLevel); } + +u32 allocate_mario_action(u32 actFlags) { + actFlags = actFlags & (~((u32)0xFF)); + return actFlags | ACT_FLAG_CUSTOM_ACTION | gLuaMarioActionIndex++; +} \ No newline at end of file diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index dfa1be07..5fdd83ed 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -11,4 +11,6 @@ bool warp_restart_level(void); bool warp_exit_level(s32 aDelay); bool warp_to_castle(s32 aLevel); +u32 allocate_mario_action(u32 actFlags); + #endif