From c2c846f6500f390a009e557ce07e94ac11676f99 Mon Sep 17 00:00:00 2001 From: Blockyyy <88585273+Blockyyy@users.noreply.github.com> Date: Wed, 15 Nov 2023 18:54:48 +0100 Subject: [PATCH] Expose lvl_set_current_level (#513) * Expose Initiate_warp exposed initiate_warp function exposed WARP_NODE_ constants * expose lvl_set_current_level * remove initiate_warp --- autogen/convert_functions.py | 2 +- autogen/lua_definitions/constants.lua | 35 +++++++++++++++++++++++++++ autogen/lua_definitions/functions.lua | 7 ++++++ docs/lua/constants.md | 16 ++++++++++++ docs/lua/functions-3.md | 21 ++++++++++++++++ docs/lua/functions.md | 1 + src/game/level_update.c | 11 --------- src/game/level_update.h | 10 ++++++++ src/pc/lua/smlua_constants_autogen.c | 11 +++++++++ src/pc/lua/smlua_functions_autogen.c | 20 +++++++++++++++ 10 files changed, 122 insertions(+), 12 deletions(-) diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index eab7b3dd..14c94bee 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -75,7 +75,7 @@ override_allowed_functions = { "src/game/object_list_processor.h": [ "set_object_respawn_info_bits" ], "src/game/mario_misc.h": [ "bhv_toad.*", "bhv_unlock_door.*" ], "src/pc/utils/misc.h": [ "update_all_mario_stars" ], - "src/game/level_update.h": [ "level_trigger_warp", "get_painting_warp_node", "initiate_painting_warp", "warp_special" ], + "src/game/level_update.h": [ "level_trigger_warp", "get_painting_warp_node", "initiate_painting_warp", "warp_special", "lvl_set_current_level" ], "src/game/area.h": [ "area_get_warp_node" ], "src/engine/level_script.h": [ "area_create_warp_node" ], "src/game/ingame_menu.h": [ "set_min_dialog_width", "set_dialog_override_pos", "reset_dialog_override_pos", "set_dialog_override_color", "reset_dialog_override_color" ] diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 36e3742f..8c2200a7 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -4040,6 +4040,30 @@ TIMER_CONTROL_START = 1 --- @type integer TIMER_CONTROL_STOP = 2 +--- @type integer +WARP_NODE_CREDITS_END = 0xFA + +--- @type integer +WARP_NODE_CREDITS_MIN = 0xF8 + +--- @type integer +WARP_NODE_CREDITS_NEXT = 0xF9 + +--- @type integer +WARP_NODE_CREDITS_START = 0xF8 + +--- @type integer +WARP_NODE_DEATH = 0xF1 + +--- @type integer +WARP_NODE_F0 = 0xF0 + +--- @type integer +WARP_NODE_F2 = 0xF2 + +--- @type integer +WARP_NODE_WARP_FLOOR = 0xF3 + --- @type integer WARP_OP_CREDITS_END = 0x15 @@ -5500,6 +5524,17 @@ PACKET_LENGTH = 3000 --- @type integer SYNC_DISTANCE_INFINITE = 0 +--- @class BouncyLevelBounds + +--- @type BouncyLevelBounds +BOUNCY_LEVEL_BOUNDS_OFF = 0 + +--- @type BouncyLevelBounds +BOUNCY_LEVEL_BOUNDS_ON = 1 + +--- @type BouncyLevelBounds +BOUNCY_LEVEL_BOUNDS_ON_CAP = 2 + --- @class NetworkSystemType --- @type NetworkSystemType diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 20bc244f..104097ff 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -4244,6 +4244,13 @@ function level_trigger_warp(m, warpOp) -- ... end +--- @param arg0 integer +--- @param levelNum integer +--- @return integer +function lvl_set_current_level(arg0, levelNum) + -- ... +end + --- @param arg integer --- @return nil function warp_special(arg) diff --git a/docs/lua/constants.md b/docs/lua/constants.md index c8bbd972..8d37c794 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -41,6 +41,7 @@ - [enum MarioHandGSCId](#enum-MarioHandGSCId) - [mod_storage.h](#mod_storageh) - [network.h](#networkh) + - [enum BouncyLevelBounds](#enum-BouncyLevelBounds) - [enum NetworkSystemType](#enum-NetworkSystemType) - [enum PlayerInteractions](#enum-PlayerInteractions) - [network_player.h](#network_playerh) @@ -1427,6 +1428,14 @@ - TIMER_CONTROL_SHOW - TIMER_CONTROL_START - TIMER_CONTROL_STOP +- WARP_NODE_CREDITS_END +- WARP_NODE_CREDITS_MIN +- WARP_NODE_CREDITS_NEXT +- WARP_NODE_CREDITS_START +- WARP_NODE_DEATH +- WARP_NODE_F0 +- WARP_NODE_F2 +- WARP_NODE_WARP_FLOOR - WARP_OP_CREDITS_END - WARP_OP_CREDITS_NEXT - WARP_OP_CREDITS_START @@ -1962,6 +1971,13 @@ - PACKET_LENGTH - SYNC_DISTANCE_INFINITE +### [enum BouncyLevelBounds](#BouncyLevelBounds) +| Identifier | Value | +| :--------- | :---- | +| BOUNCY_LEVEL_BOUNDS_OFF | 0 | +| BOUNCY_LEVEL_BOUNDS_ON | 1 | +| BOUNCY_LEVEL_BOUNDS_ON_CAP | 2 | + ### [enum NetworkSystemType](#NetworkSystemType) | Identifier | Value | | :--------- | :---- | diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index 7a966539..5cccefc3 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -4030,6 +4030,27 @@
+## [lvl_set_current_level](#lvl_set_current_level) + +### Lua Example +`local integerValue = lvl_set_current_level(arg0, levelNum)` + +### Parameters +| Field | Type | +| ----- | ---- | +| arg0 | `integer` | +| levelNum | `integer` | + +### Returns +- `integer` + +### C Prototype +`s32 lvl_set_current_level(UNUSED s16 arg0, s32 levelNum);` + +[:arrow_up_small:](#) + +
+ ## [warp_special](#warp_special) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index b94ebf35..d88ac6f6 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -859,6 +859,7 @@ - [get_painting_warp_node](functions-3.md#get_painting_warp_node) - [initiate_painting_warp](functions-3.md#initiate_painting_warp) - [level_trigger_warp](functions-3.md#level_trigger_warp) + - [lvl_set_current_level](functions-3.md#lvl_set_current_level) - [warp_special](functions-3.md#warp_special)
diff --git a/src/game/level_update.c b/src/game/level_update.c index 38f3b6a1..8b843363 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -48,17 +48,6 @@ #include "engine/level_script.h" -#include "mario_actions_cutscene.h" - -#define WARP_NODE_F0 0xF0 -#define WARP_NODE_DEATH 0xF1 -#define WARP_NODE_F2 0xF2 -#define WARP_NODE_WARP_FLOOR 0xF3 -#define WARP_NODE_CREDITS_START 0xF8 -#define WARP_NODE_CREDITS_NEXT 0xF9 -#define WARP_NODE_CREDITS_END 0xFA -#define WARP_NODE_CREDITS_MIN 0xF8 - #define MENU_LEVEL_MIN 0 #define MENU_LEVEL_MAX 17 diff --git a/src/game/level_update.h b/src/game/level_update.h index f9c2b0eb..514af0e1 100644 --- a/src/game/level_update.h +++ b/src/game/level_update.h @@ -58,6 +58,15 @@ #define MARIO_SPAWN_LAUNCH_DEATH 0x25 #define MARIO_SPAWN_UNKNOWN_27 0x27 +#define WARP_NODE_F0 0xF0 +#define WARP_NODE_DEATH 0xF1 +#define WARP_NODE_F2 0xF2 +#define WARP_NODE_WARP_FLOOR 0xF3 +#define WARP_NODE_CREDITS_START 0xF8 +#define WARP_NODE_CREDITS_NEXT 0xF9 +#define WARP_NODE_CREDITS_END 0xFA +#define WARP_NODE_CREDITS_MIN 0xF8 + #define WARP_TYPE_NOT_WARPING 0 #define WARP_TYPE_CHANGE_LEVEL 1 #define WARP_TYPE_CHANGE_AREA 2 @@ -162,6 +171,7 @@ void initiate_painting_warp(s16 paintingIndex); s16 level_trigger_warp(struct MarioState *m, s32 warpOp); void level_set_transition(s16 length, void (*updateFunction)(s16 *)); void warp_special(s32 arg); +void initiate_warp(s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg3); s32 lvl_init_or_update(s16 initOrUpdate, UNUSED s32 unused); s32 lvl_init_from_save_file(UNUSED s16 arg0, s32 levelNum); diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index fb82b08a..5e81d959 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -1569,6 +1569,14 @@ char gSmluaConstants[] = "" "MARIO_SPAWN_LAUNCH_STAR_COLLECT = 0x24\n" "MARIO_SPAWN_LAUNCH_DEATH = 0x25\n" "MARIO_SPAWN_UNKNOWN_27 = 0x27\n" +"WARP_NODE_F0 = 0xF0\n" +"WARP_NODE_DEATH = 0xF1\n" +"WARP_NODE_F2 = 0xF2\n" +"WARP_NODE_WARP_FLOOR = 0xF3\n" +"WARP_NODE_CREDITS_START = 0xF8\n" +"WARP_NODE_CREDITS_NEXT = 0xF9\n" +"WARP_NODE_CREDITS_END = 0xFA\n" +"WARP_NODE_CREDITS_MIN = 0xF8\n" "WARP_TYPE_NOT_WARPING = 0\n" "WARP_TYPE_CHANGE_LEVEL = 1\n" "WARP_TYPE_CHANGE_AREA = 2\n" @@ -2040,6 +2048,9 @@ char gSmluaConstants[] = "" "PLAYER_INTERACTIONS_NONE = 0\n" "PLAYER_INTERACTIONS_SOLID = 1\n" "PLAYER_INTERACTIONS_PVP = 2\n" +"BOUNCY_LEVEL_BOUNDS_OFF = 0\n" +"BOUNCY_LEVEL_BOUNDS_ON = 1\n" +"BOUNCY_LEVEL_BOUNDS_ON_CAP = 2\n" "UNKNOWN_LOCAL_INDEX = (-1)\n" "UNKNOWN_GLOBAL_INDEX = (-1)\n" "UNKNOWN_NETWORK_INDEX = (-1)\n" diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 5ac0cd4c..8edc2f60 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -13867,6 +13867,25 @@ int smlua_func_level_trigger_warp(lua_State* L) { return 1; } +int smlua_func_lvl_set_current_level(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 2) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "lvl_set_current_level", 2, top); + return 0; + } + + s16 arg0 = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "lvl_set_current_level"); return 0; } + s32 levelNum = smlua_to_integer(L, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "lvl_set_current_level"); return 0; } + + lua_pushinteger(L, lvl_set_current_level(arg0, levelNum)); + + return 1; +} + int smlua_func_warp_special(lua_State* L) { if (L == NULL) { return 0; } @@ -32084,6 +32103,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "get_painting_warp_node", smlua_func_get_painting_warp_node); smlua_bind_function(L, "initiate_painting_warp", smlua_func_initiate_painting_warp); smlua_bind_function(L, "level_trigger_warp", smlua_func_level_trigger_warp); + smlua_bind_function(L, "lvl_set_current_level", smlua_func_lvl_set_current_level); smlua_bind_function(L, "warp_special", smlua_func_warp_special); // mario.h