From 748b7e91347ba3bb66597890ca133137858b3bb8 Mon Sep 17 00:00:00 2001
From: Emerald Lockdown <86802223+EmeraldLoc@users.noreply.github.com>
Date: Thu, 25 Aug 2022 19:27:05 -0500
Subject: [PATCH] Added `warp_to_start_level` function (#154)
* Added `warp_to_start_level` function
* Fix include things
---
autogen/lua_definitions/functions.lua | 5 +++++
data/dynos.c.h | 1 +
data/dynos_c.cpp | 13 ++++++++++++-
docs/lua/functions-4.md | 18 ++++++++++++++++++
docs/lua/functions.md | 1 +
src/pc/lua/smlua_functions_autogen.c | 10 ++++++++++
src/pc/lua/utils/smlua_level_utils.c | 4 ++++
src/pc/lua/utils/smlua_level_utils.h | 1 +
8 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 71002c917..c9aa21a46 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -7527,6 +7527,11 @@ function warp_to_level(aLevel, aArea, aAct)
-- ...
end
+--- @return boolean
+function warp_to_start_level()
+ -- ...
+end
+
--- @param actFlags integer
--- @return integer
function allocate_mario_action(actFlags)
diff --git a/data/dynos.c.h b/data/dynos.c.h
index fb415c05a..4c0d5782e 100644
--- a/data/dynos.c.h
+++ b/data/dynos.c.h
@@ -20,6 +20,7 @@ void dynos_gfx_swap_animations(void *ptr);
LevelScript* dynos_get_level_script(char* scriptEntryName);
bool dynos_warp_to_level(s32 aLevel, s32 aArea, s32 aAct);
bool dynos_warp_restart_level(void);
+bool dynos_warp_to_start_level(void);
bool dynos_warp_exit_level(s32 aDelay);
bool dynos_warp_to_castle(s32 aLevel);
diff --git a/data/dynos_c.cpp b/data/dynos_c.cpp
index e8e27f5cc..f5f79578a 100644
--- a/data/dynos_c.cpp
+++ b/data/dynos_c.cpp
@@ -1,6 +1,7 @@
#include "dynos.cpp.h"
extern "C" {
#include "src/game/moving_texture.h"
+#include "game/hardcoded.h"
void *dynos_swap_cmd(void *cmd) {
return DynOS_SwapCmd(cmd);
@@ -38,6 +39,16 @@ bool dynos_warp_to_level(s32 aLevel, s32 aArea, s32 aAct) {
return DynOS_Warp_ToLevel(aLevel, aArea, aAct);
}
+bool dynos_warp_to_start_level(void) {
+
+ // change the level to the start level
+ extern s16 gChangeLevel;
+ gChangeLevel = gLevelValues.entryLevel;
+
+ // always return true since it will always suceed
+ return true;
+}
+
bool dynos_warp_restart_level(void) {
return DynOS_Warp_RestartLevel();
}
@@ -187,4 +198,4 @@ void dynos_mod_shutdown(void) {
DynOS_Mod_Shutdown();
}
-}
\ No newline at end of file
+}
diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md
index 3f3912212..dd91a66e5 100644
--- a/docs/lua/functions-4.md
+++ b/docs/lua/functions-4.md
@@ -6286,6 +6286,24 @@
+## [warp_to_start_level](#warp_to_start_level)
+
+### Lua Example
+`local booleanValue = warp_to_start_level()`
+
+### Parameters
+- None
+
+### Returns
+- `boolean`
+
+### C Prototype
+`bool warp_to_start_level(void);`
+
+[:arrow_up_small:](#)
+
+
+
---
# functions from smlua_misc_utils.h
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 522e45575..014ca32d3 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1400,6 +1400,7 @@
- [warp_restart_level](functions-4.md#warp_restart_level)
- [warp_to_castle](functions-4.md#warp_to_castle)
- [warp_to_level](functions-4.md#warp_to_level)
+ - [warp_to_start_level](functions-4.md#warp_to_start_level)
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index b88d07edc..2299f8a71 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -16635,6 +16635,15 @@ int smlua_func_warp_to_level(lua_State* L) {
return 1;
}
+int smlua_func_warp_to_start_level(UNUSED lua_State* L) {
+ if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
+
+
+ lua_pushboolean(L, warp_to_start_level());
+
+ return 1;
+}
+
////////////////////////
// smlua_misc_utils.h //
////////////////////////
@@ -19426,6 +19435,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "warp_restart_level", smlua_func_warp_restart_level);
smlua_bind_function(L, "warp_to_castle", smlua_func_warp_to_castle);
smlua_bind_function(L, "warp_to_level", smlua_func_warp_to_level);
+ smlua_bind_function(L, "warp_to_start_level", smlua_func_warp_to_start_level);
// smlua_misc_utils.h
smlua_bind_function(L, "allocate_mario_action", smlua_func_allocate_mario_action);
diff --git a/src/pc/lua/utils/smlua_level_utils.c b/src/pc/lua/utils/smlua_level_utils.c
index 5310cd8ed..dae54ea87 100644
--- a/src/pc/lua/utils/smlua_level_utils.c
+++ b/src/pc/lua/utils/smlua_level_utils.c
@@ -130,6 +130,10 @@ bool warp_to_level(s32 aLevel, s32 aArea, s32 aAct) {
return dynos_warp_to_level(aLevel, aArea, aAct);
}
+bool warp_to_start_level(void) {
+ return dynos_warp_to_start_level();
+}
+
bool warp_restart_level(void) {
return dynos_warp_restart_level();
}
diff --git a/src/pc/lua/utils/smlua_level_utils.h b/src/pc/lua/utils/smlua_level_utils.h
index c151b3c25..473e2043a 100644
--- a/src/pc/lua/utils/smlua_level_utils.h
+++ b/src/pc/lua/utils/smlua_level_utils.h
@@ -23,6 +23,7 @@ struct CustomLevelInfo* smlua_level_util_get_info_from_short_name(char* shortNam
s16 level_register(const char* scriptEntryName, s16 courseNum, const char* fullName, const char* shortName, u32 acousticReach, u32 echoLevel1, u32 echoLevel2, u32 echoLevel3);
bool warp_to_level(s32 aLevel, s32 aArea, s32 aAct);
bool warp_restart_level(void);
+bool warp_to_start_level(void);
bool warp_exit_level(s32 aDelay);
bool warp_to_castle(s32 aLevel);