From acd14c27188d050b4ed9930f3e90220436265973 Mon Sep 17 00:00:00 2001
From: Isaac <62234577+Isaac0-dev@users.noreply.github.com>
Date: Thu, 24 Mar 2022 13:48:06 +1000
Subject: [PATCH 1/2] Fixed desync for late joiners when using Non-stop mode
and made bubble when no lives remaining kick you out of the level (#40)
---
src/game/interaction.c | 1 +
src/game/mario_actions_automatic.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/src/game/interaction.c b/src/game/interaction.c
index 5b46addee..ee2ae40b2 100644
--- a/src/game/interaction.c
+++ b/src/game/interaction.c
@@ -944,6 +944,7 @@ u32 interact_star_or_key(struct MarioState *m, UNUSED u32 interactType, struct O
if (grandStar) {
return set_mario_action(m, ACT_JUMBO_STAR_CUTSCENE, 0);
}
+ save_file_do_save(gCurrSaveFileNum - 1, TRUE);
if (!noExit || gServerSettings.stayInLevelAfterStar != 2) {
return set_mario_action(m, starGrabAction, noExit + 2 * grandStar);
diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c
index 4cb40a779..595f67b64 100644
--- a/src/game/mario_actions_automatic.c
+++ b/src/game/mario_actions_automatic.c
@@ -1016,6 +1016,8 @@ s32 act_bubbled(struct MarioState* m) {
if (m->playerIndex == 0) {
if (m->numLives == -1) {
m->marioObj->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE;
+ level_trigger_warp(m, WARP_OP_DEATH);
+ return set_mario_action(m, ACT_SOFT_BONK, 0);
} else {
m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
}
From 65df754b09295bc4db042778a0174f2eb3b3eabe Mon Sep 17 00:00:00 2001
From: Isaac <62234577+Isaac0-dev@users.noreply.github.com>
Date: Fri, 25 Mar 2022 12:30:15 +1000
Subject: [PATCH 2/2] Add save file flag functions to lua api (#41)
---
autogen/convert_constants.py | 1 +
autogen/convert_functions.py | 2 +-
autogen/lua_definitions/constants.lua | 98 +++++++++++++++++++++++++++
autogen/lua_definitions/functions.lua | 12 ++++
docs/lua/constants.md | 44 ++++++++++++
docs/lua/functions.md | 42 ++++++++++++
src/pc/lua/smlua_constants_autogen.c | 32 +++++++++
src/pc/lua/smlua_functions_autogen.c | 24 +++++++
8 files changed, 254 insertions(+), 1 deletion(-)
diff --git a/autogen/convert_constants.py b/autogen/convert_constants.py
index 8e681493d..079cb4d25 100644
--- a/autogen/convert_constants.py
+++ b/autogen/convert_constants.py
@@ -29,6 +29,7 @@ in_files = [
"src/engine/graph_node.h",
"levels/level_defines.h",
"src/game/obj_behaviors.c",
+ "src/game/save_file.h",
]
exclude_constants = {
diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py
index 4ebfdc16a..56075a530 100644
--- a/autogen/convert_functions.py
+++ b/autogen/convert_functions.py
@@ -52,7 +52,7 @@ override_allowed_functions = {
"src/game/camera.h": [ "set_.*camera_.*shake", "set_camera_mode" ],
"src/game/rumble_init.c": [ "queue_rumble_", "reset_rumble_timers" ],
"src/pc/djui/djui_popup.h" : [ "create" ],
- "src/game/save_file.h": [ "save_file_get_" ],
+ "src/game/save_file.h": [ "save_file_get_", "save_file_set_flags", "save_file_clear_flags" ],
"src/pc/lua/utils/smlua_model_utils.h": [ "smlua_model_util_get_id" ],
}
diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua
index 787f54768..7e13c4f06 100644
--- a/autogen/lua_definitions/constants.lua
+++ b/autogen/lua_definitions/constants.lua
@@ -4208,6 +4208,104 @@ Y_BUTTON = CONT_Y
--- @type integer
Z_TRIG = CONT_G
+--- @type integer
+EEPROM_SIZE = 0x200
+
+--- @type integer
+NUM_SAVE_FILES = 4
+
+--- @type integer
+SAVE_FLAG_CAP_ON_GROUND = (1 << 16)
+
+--- @type integer
+SAVE_FLAG_CAP_ON_KLEPTO = (1 << 17)
+
+--- @type integer
+SAVE_FLAG_CAP_ON_MR_BLIZZARD = (1 << 19)
+
+--- @type integer
+SAVE_FLAG_CAP_ON_UKIKI = (1 << 18)
+
+--- @type integer
+SAVE_FLAG_COLLECTED_MIPS_STAR_1 = (1 << 27)
+
+--- @type integer
+SAVE_FLAG_COLLECTED_MIPS_STAR_2 = (1 << 28)
+
+--- @type integer
+SAVE_FLAG_COLLECTED_TOAD_STAR_1 = (1 << 24)
+
+--- @type integer
+SAVE_FLAG_COLLECTED_TOAD_STAR_2 = (1 << 25)
+
+--- @type integer
+SAVE_FLAG_COLLECTED_TOAD_STAR_3 = (1 << 26)
+
+--- @type integer
+SAVE_FLAG_DDD_MOVED_BACK = (1 << 8)
+
+--- @type integer
+SAVE_FLAG_FILE_EXISTS = (1 << 0)
+
+--- @type integer
+SAVE_FLAG_HAVE_KEY_1 = (1 << 4)
+
+--- @type integer
+SAVE_FLAG_HAVE_KEY_2 = (1 << 5)
+
+--- @type integer
+SAVE_FLAG_HAVE_METAL_CAP = (1 << 2)
+
+--- @type integer
+SAVE_FLAG_HAVE_VANISH_CAP = (1 << 3)
+
+--- @type integer
+SAVE_FLAG_HAVE_WING_CAP = (1 << 1)
+
+--- @type integer
+SAVE_FLAG_MOAT_DRAINED = (1 << 9)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_50_STAR_DOOR = (1 << 20)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_BASEMENT_DOOR = (1 << 6)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_BITDW_DOOR = (1 << 14)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_BITFS_DOOR = (1 << 15)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_CCM_DOOR = (1 << 12)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_JRB_DOOR = (1 << 13)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_PSS_DOOR = (1 << 10)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR = (1 << 7)
+
+--- @type integer
+SAVE_FLAG_UNLOCKED_WF_DOOR = (1 << 11)
+
+--- @class SaveFileIndex
+
+--- @type SaveFileIndex
+SAVE_FILE_A = 0
+
+--- @type SaveFileIndex
+SAVE_FILE_B = 1
+
+--- @type SaveFileIndex
+SAVE_FILE_C = 2
+
+--- @type SaveFileIndex
+SAVE_FILE_D = 3
+
--- @type integer
ACT_AIR_HIT_WALL = 0x000008A7
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index bba404f46..faf67a959 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -3427,6 +3427,12 @@ function reset_rumble_timers_2(m, a0)
-- ...
end
+--- @param flags integer
+--- @return nil
+function save_file_clear_flags(flags)
+ -- ...
+end
+
--- @param capPos Vec3s
--- @return integer
function save_file_get_cap_pos(capPos)
@@ -3478,6 +3484,12 @@ function save_file_get_total_star_count(fileIndex, minCourse, maxCourse)
-- ...
end
+--- @param flags integer
+--- @return nil
+function save_file_set_flags(flags)
+ -- ...
+end
+
--- @param startX number
--- @param startY number
--- @param startZ number
diff --git a/docs/lua/constants.md b/docs/lua/constants.md
index 416506072..3287371bf 100644
--- a/docs/lua/constants.md
+++ b/docs/lua/constants.md
@@ -31,6 +31,8 @@
- [object_list_processor.h](#object_list_processorh)
- [enum ObjectList](#enum-ObjectList)
- [os_cont.h](#os_conth)
+- [save_file.h](#save_fileh)
+ - [enum SaveFileIndex](#enum-SaveFileIndex)
- [sm64.h](#sm64h)
- [smlua_hooks.h](#smlua_hooksh)
- [enum LuaHookedEventType](#enum-LuaHookedEventType)
@@ -1495,6 +1497,48 @@
+## [save_file.h](#save_file.h)
+- EEPROM_SIZE
+- NUM_SAVE_FILES
+- SAVE_FLAG_CAP_ON_GROUND
+- SAVE_FLAG_CAP_ON_KLEPTO
+- SAVE_FLAG_CAP_ON_MR_BLIZZARD
+- SAVE_FLAG_CAP_ON_UKIKI
+- SAVE_FLAG_COLLECTED_MIPS_STAR_1
+- SAVE_FLAG_COLLECTED_MIPS_STAR_2
+- SAVE_FLAG_COLLECTED_TOAD_STAR_1
+- SAVE_FLAG_COLLECTED_TOAD_STAR_2
+- SAVE_FLAG_COLLECTED_TOAD_STAR_3
+- SAVE_FLAG_DDD_MOVED_BACK
+- SAVE_FLAG_FILE_EXISTS
+- SAVE_FLAG_HAVE_KEY_1
+- SAVE_FLAG_HAVE_KEY_2
+- SAVE_FLAG_HAVE_METAL_CAP
+- SAVE_FLAG_HAVE_VANISH_CAP
+- SAVE_FLAG_HAVE_WING_CAP
+- SAVE_FLAG_MOAT_DRAINED
+- SAVE_FLAG_UNLOCKED_50_STAR_DOOR
+- SAVE_FLAG_UNLOCKED_BASEMENT_DOOR
+- SAVE_FLAG_UNLOCKED_BITDW_DOOR
+- SAVE_FLAG_UNLOCKED_BITFS_DOOR
+- SAVE_FLAG_UNLOCKED_CCM_DOOR
+- SAVE_FLAG_UNLOCKED_JRB_DOOR
+- SAVE_FLAG_UNLOCKED_PSS_DOOR
+- SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR
+- SAVE_FLAG_UNLOCKED_WF_DOOR
+
+### [enum SaveFileIndex](#SaveFileIndex)
+| Identifier | Value |
+| :--------- | :---- |
+| SAVE_FILE_A | 0 |
+| SAVE_FILE_B | 1 |
+| SAVE_FILE_C | 2 |
+| SAVE_FILE_D | 3 |
+
+[:arrow_up_small:](#)
+
+
+
## [sm64.h](#sm64.h)
- ACT_AIR_HIT_WALL
- ACT_AIR_THROW
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 903b71c5c..e5ead5d2f 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -619,6 +619,7 @@
- save_file.h
+ - [save_file_clear_flags](#save_file_clear_flags)
- [save_file_get_cap_pos](#save_file_get_cap_pos)
- [save_file_get_course_coin_score](#save_file_get_course_coin_score)
- [save_file_get_course_star_count](#save_file_get_course_star_count)
@@ -627,6 +628,7 @@
- [save_file_get_sound_mode](#save_file_get_sound_mode)
- [save_file_get_star_flags](#save_file_get_star_flags)
- [save_file_get_total_star_count](#save_file_get_total_star_count)
+ - [save_file_set_flags](#save_file_set_flags)
@@ -11464,6 +11466,26 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [save_file_clear_flags](#save_file_clear_flags)
+
+### Lua Example
+`save_file_clear_flags(flags)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| flags | `integer` |
+
+### Returns
+- None
+
+### C Prototype
+`void save_file_clear_flags(u32 flags);`
+
+[:arrow_up_small:](#)
+
+
+
## [save_file_get_cap_pos](#save_file_get_cap_pos)
### Lua Example
@@ -11625,6 +11647,26 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [save_file_set_flags](#save_file_set_flags)
+
+### Lua Example
+`save_file_set_flags(flags)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| flags | `integer` |
+
+### Returns
+- None
+
+### C Prototype
+`void save_file_set_flags(u32 flags);`
+
+[:arrow_up_small:](#)
+
+
+
---
# functions from smlua_collision_utils.h
diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c
index 1fed4e747..570dbd4c3 100644
--- a/src/pc/lua/smlua_constants_autogen.c
+++ b/src/pc/lua/smlua_constants_autogen.c
@@ -1546,6 +1546,38 @@ char gSmluaConstants[] = ""
"L_CBUTTONS = CONT_C\n"
"R_CBUTTONS = CONT_F\n"
"D_CBUTTONS = CONT_D\n"
+"EEPROM_SIZE = 0x200\n"
+"NUM_SAVE_FILES = 4\n"
+"SAVE_FILE_A = 0\n"
+"SAVE_FILE_B = 1\n"
+"SAVE_FILE_C = 2\n"
+"SAVE_FILE_D = 3\n"
+"SAVE_FLAG_FILE_EXISTS = (1 << 0)\n"
+"SAVE_FLAG_HAVE_WING_CAP = (1 << 1)\n"
+"SAVE_FLAG_HAVE_METAL_CAP = (1 << 2)\n"
+"SAVE_FLAG_HAVE_VANISH_CAP = (1 << 3)\n"
+"SAVE_FLAG_HAVE_KEY_1 = (1 << 4)\n"
+"SAVE_FLAG_HAVE_KEY_2 = (1 << 5)\n"
+"SAVE_FLAG_UNLOCKED_BASEMENT_DOOR = (1 << 6)\n"
+"SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR = (1 << 7)\n"
+"SAVE_FLAG_DDD_MOVED_BACK = (1 << 8)\n"
+"SAVE_FLAG_MOAT_DRAINED = (1 << 9)\n"
+"SAVE_FLAG_UNLOCKED_PSS_DOOR = (1 << 10)\n"
+"SAVE_FLAG_UNLOCKED_WF_DOOR = (1 << 11)\n"
+"SAVE_FLAG_UNLOCKED_CCM_DOOR = (1 << 12)\n"
+"SAVE_FLAG_UNLOCKED_JRB_DOOR = (1 << 13)\n"
+"SAVE_FLAG_UNLOCKED_BITDW_DOOR = (1 << 14)\n"
+"SAVE_FLAG_UNLOCKED_BITFS_DOOR = (1 << 15)\n"
+"SAVE_FLAG_CAP_ON_GROUND = (1 << 16)\n"
+"SAVE_FLAG_CAP_ON_KLEPTO = (1 << 17)\n"
+"SAVE_FLAG_CAP_ON_UKIKI = (1 << 18)\n"
+"SAVE_FLAG_CAP_ON_MR_BLIZZARD = (1 << 19)\n"
+"SAVE_FLAG_UNLOCKED_50_STAR_DOOR = (1 << 20)\n"
+"SAVE_FLAG_COLLECTED_TOAD_STAR_1 = (1 << 24)\n"
+"SAVE_FLAG_COLLECTED_TOAD_STAR_2 = (1 << 25)\n"
+"SAVE_FLAG_COLLECTED_TOAD_STAR_3 = (1 << 26)\n"
+"SAVE_FLAG_COLLECTED_MIPS_STAR_1 = (1 << 27)\n"
+"SAVE_FLAG_COLLECTED_MIPS_STAR_2 = (1 << 28)\n"
"LAYER_FORCE = 0\n"
"LAYER_OPAQUE = 1\n"
"LAYER_OPAQUE_DECAL = 2\n"
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 5eb027f01..800d22836 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -7293,6 +7293,17 @@ int smlua_func_reset_rumble_timers_2(lua_State* L) {
// save_file.h //
/////////////////
+int smlua_func_save_file_clear_flags(lua_State* L) {
+ if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
+
+ u32 flags = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { return 0; }
+
+ save_file_clear_flags(flags);
+
+ return 1;
+}
+
int smlua_func_save_file_get_cap_pos(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
@@ -7397,6 +7408,17 @@ int smlua_func_save_file_get_total_star_count(lua_State* L) {
return 1;
}
+int smlua_func_save_file_set_flags(lua_State* L) {
+ if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
+
+ u32 flags = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { return 0; }
+
+ save_file_set_flags(flags);
+
+ return 1;
+}
+
/////////////////////////////
// smlua_collision_utils.h //
/////////////////////////////
@@ -8843,6 +8865,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "reset_rumble_timers_2", smlua_func_reset_rumble_timers_2);
// save_file.h
+ smlua_bind_function(L, "save_file_clear_flags", smlua_func_save_file_clear_flags);
smlua_bind_function(L, "save_file_get_cap_pos", smlua_func_save_file_get_cap_pos);
smlua_bind_function(L, "save_file_get_course_coin_score", smlua_func_save_file_get_course_coin_score);
smlua_bind_function(L, "save_file_get_course_star_count", smlua_func_save_file_get_course_star_count);
@@ -8851,6 +8874,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "save_file_get_sound_mode", smlua_func_save_file_get_sound_mode);
smlua_bind_function(L, "save_file_get_star_flags", smlua_func_save_file_get_star_flags);
smlua_bind_function(L, "save_file_get_total_star_count", smlua_func_save_file_get_total_star_count);
+ smlua_bind_function(L, "save_file_set_flags", smlua_func_save_file_set_flags);
// smlua_collision_utils.h
smlua_bind_function(L, "collision_find_surface_on_ray", smlua_func_collision_find_surface_on_ray);