diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py
index 3e25b2c5..b0a14bdb 100644
--- a/autogen/convert_functions.py
+++ b/autogen/convert_functions.py
@@ -52,6 +52,7 @@ in_files = [
"src/game/object_list_processor.h",
"src/game/behavior_actions.h",
"src/game/mario_misc.h",
+ "src/pc/utils/misc.h",
"src/game/level_update.h"
]
@@ -59,11 +60,12 @@ override_allowed_functions = {
"src/audio/external.h": [ " play_", "fade", "current_background", "stop_" ],
"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_", "save_file_set_flags", "save_file_clear_flags", "save_file_reload", "save_file_set_star_flags" ],
+ "src/game/save_file.h": [ "save_file_get_", "save_file_set_flags", "save_file_clear_flags", "save_file_reload", "save_file_erase_current_backup_save", "save_file_set_star_flags" ],
"src/pc/lua/utils/smlua_model_utils.h": [ "smlua_model_util_get_id" ],
"src/game/object_list_processor.h": [ "set_object_respawn_info_bits" ],
"src/game/mario_misc.h": [ "bhv_toad.*", "bhv_unlock_door.*" ],
"src/game/level_update.h": [ "level_trigger_warp" ],
+ "src/pc/utils/misc.h": [ "update_all_mario_stars"],
}
override_disallowed_functions = {
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 9f7761aa..d3c5c6fd 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -5211,6 +5211,11 @@ function vec3f_set_dist_and_angle(from, to, dist, pitch, yaw)
-- ...
end
+--- @return nil
+function update_all_mario_stars()
+ -- ...
+end
+
--- @param courseNum integer
--- @param actNum integer
--- @param levelNum integer
@@ -7271,6 +7276,11 @@ function save_file_clear_flags(flags)
-- ...
end
+--- @return nil
+function save_file_erase_current_backup_save()
+ -- ...
+end
+
--- @param capPos Vec3s
--- @return integer
function save_file_get_cap_pos(capPos)
@@ -7322,8 +7332,9 @@ function save_file_get_total_star_count(fileIndex, minCourse, maxCourse)
-- ...
end
+--- @param load_all integer
--- @return nil
-function save_file_reload()
+function save_file_reload(load_all)
-- ...
end
diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md
index d7707e79..ff2bc033 100644
--- a/docs/lua/functions-3.md
+++ b/docs/lua/functions-3.md
@@ -7095,6 +7095,30 @@
+---
+# functions from misc.h
+
+
+
+
+## [update_all_mario_stars](#update_all_mario_stars)
+
+### Lua Example
+`update_all_mario_stars()`
+
+### Parameters
+- None
+
+### Returns
+- None
+
+### C Prototype
+`void update_all_mario_stars(void);`
+
+[:arrow_up_small:](#)
+
+
+
---
# functions from network_player.h
diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md
index f7caf398..7d159334 100644
--- a/docs/lua/functions-4.md
+++ b/docs/lua/functions-4.md
@@ -5364,6 +5364,24 @@
+## [save_file_erase_current_backup_save](#save_file_erase_current_backup_save)
+
+### Lua Example
+`save_file_erase_current_backup_save()`
+
+### Parameters
+- None
+
+### Returns
+- None
+
+### C Prototype
+`void save_file_erase_current_backup_save(void);`
+
+[:arrow_up_small:](#)
+
+
+
## [save_file_get_cap_pos](#save_file_get_cap_pos)
### Lua Example
@@ -5528,16 +5546,18 @@
## [save_file_reload](#save_file_reload)
### Lua Example
-`save_file_reload()`
+`save_file_reload(load_all)`
### Parameters
-- None
+| Field | Type |
+| ----- | ---- |
+| load_all | `integer` |
### Returns
- None
### C Prototype
-`void save_file_reload(void);`
+`void save_file_reload(u8 load_all);`
[:arrow_up_small:](#)
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 8da00408..2bf3e70a 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1012,6 +1012,11 @@
+- misc.h
+ - [update_all_mario_stars](functions-3.md#update_all_mario_stars)
+
+
+
- network_player.h
- [get_network_player_from_area](functions-3.md#get_network_player_from_area)
- [get_network_player_from_level](functions-3.md#get_network_player_from_level)
@@ -1354,6 +1359,7 @@
- save_file.h
- [save_file_clear_flags](functions-4.md#save_file_clear_flags)
+ - [save_file_erase_current_backup_save](functions-4.md#save_file_erase_current_backup_save)
- [save_file_get_cap_pos](functions-4.md#save_file_get_cap_pos)
- [save_file_get_course_coin_score](functions-4.md#save_file_get_course_coin_score)
- [save_file_get_course_star_count](functions-4.md#save_file_get_course_star_count)
diff --git a/src/game/save_file.c b/src/game/save_file.c
index cf565657..0480eedf 100644
--- a/src/game/save_file.c
+++ b/src/game/save_file.c
@@ -14,6 +14,7 @@
#include "pc/ini.h"
#include "pc/network/network.h"
#include "pc/lua/utils/smlua_level_utils.h"
+#include "pc/utils/misc.h"
#ifndef bcopy
#define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0)
@@ -200,7 +201,7 @@ static u16 calc_checksum(u8 *data, s32 size) {
/**
* Verify the signature at the end of the block to check if the data is valid.
*/
-static s32 verify_save_block_signature(void *buffer, s32 size, u16 magic) {
+UNUSED static s32 verify_save_block_signature(void *buffer, s32 size, u16 magic) {
struct SaveBlockSignature *sig = (struct SaveBlockSignature *) ((size - 4) + (u8 *) buffer);
if (sig->magic != magic) {
@@ -225,7 +226,7 @@ static void add_save_block_signature(void *buffer, s32 size, u16 magic) {
/**
* Copy main menu data from one backup slot to the other slot.
*/
-static void restore_main_menu_data(s32 srcSlot) {
+UNUSED static void restore_main_menu_data(s32 srcSlot) {
s32 destSlot = srcSlot ^ 1;
// Compute checksum on source data
@@ -253,7 +254,7 @@ static void save_main_menu_data(void) {
}
}
-static void wipe_main_menu_data(void) {
+UNUSED static void wipe_main_menu_data(void) {
bzero(&gSaveBuffer.menuData[0], sizeof(gSaveBuffer.menuData[0]));
// Set score ages for all courses to 3, 2, 1, and 0, respectively.
@@ -311,7 +312,7 @@ static void touch_high_score_ages(s32 fileIndex) {
/**
* Copy save file data from one backup slot to the other slot.
*/
-static void restore_save_file_data(s32 fileIndex, s32 srcSlot) {
+UNUSED static void restore_save_file_data(s32 fileIndex, s32 srcSlot) {
s32 destSlot = srcSlot ^ 1;
// Compute checksum on source data
@@ -392,6 +393,28 @@ void save_file_erase(s32 fileIndex) {
save_file_do_save(fileIndex, TRUE);
}
+void save_file_reload(u8 load_all) {
+ gSaveFileModified = TRUE;
+ update_all_mario_stars();
+
+ if (load_all == TRUE) {
+ save_file_load_all(TRUE);
+ save_file_do_save(gCurrSaveFileNum-1, TRUE);
+ update_all_mario_stars();
+ }
+}
+
+void save_file_erase_current_backup_save(void) {
+ if (network_is_server()) {
+ bzero(&gSaveBuffer.files[gCurrSaveFileNum-1][1], sizeof(gSaveBuffer.files[gCurrSaveFileNum-1][1]));
+
+ save_file_reload(FALSE);
+
+ save_file_do_save(gCurrSaveFileNum-1, TRUE);
+ network_send_save_file(gCurrSaveFileNum-1);
+ }
+}
+
//! Needs to be s32 to match on -O2, despite no return value.
BAD_RETURN(s32) save_file_copy(s32 srcFileIndex, s32 destFileIndex) {
if (srcFileIndex < 0 || srcFileIndex >= NUM_SAVE_FILES || destFileIndex < 0 || destFileIndex >= NUM_SAVE_FILES)
@@ -457,23 +480,6 @@ void save_file_load_all(UNUSED u8 reload) {
stub_save_file_1();
}
-/**
- * Reload the current save file from its backup copy, which is effectively a
- * a cached copy of what has been written to EEPROM.
- * This is used after getting a game over.
- */
-void save_file_reload(void) {
- // Copy save file data from backup
- /*bcopy(&gSaveBuffer.files[gCurrSaveFileNum - 1][1], &gSaveBuffer.files[gCurrSaveFileNum - 1][0],
- sizeof(gSaveBuffer.files[gCurrSaveFileNum - 1][0]));
-
- // Copy main menu data from backup
- bcopy(&gSaveBuffer.menuData[1], &gSaveBuffer.menuData[0], sizeof(gSaveBuffer.menuData[0]));*/
-
- gMainMenuDataModified = FALSE;
- gSaveFileModified = FALSE;
-}
-
/**
* Update the current save file after collecting a star or a key.
* If coin score is greater than the current high score, update it.
diff --git a/src/game/save_file.h b/src/game/save_file.h
index 97d3f379..6aca7221 100644
--- a/src/game/save_file.h
+++ b/src/game/save_file.h
@@ -131,9 +131,10 @@ extern s8 gSaveFileModified;
s8 get_level_course_num(s16 levelNum);
void save_file_do_save(s32 fileIndex, s8 forceSave);
void save_file_erase(s32 fileIndex);
+void save_file_erase_current_backup_save(void);
BAD_RETURN(s32) save_file_copy(s32 srcFileIndex, s32 destFileIndex);
void save_file_load_all(u8 reload);
-void save_file_reload(void);
+void save_file_reload(u8 load_all);
void save_file_collect_star_or_key(s16 coinScore, s16 starIndex, u8 fromNetwork);
s32 save_file_exists(s32 fileIndex);
u32 save_file_get_max_coin_score(s32 courseIndex);
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 7699bf83..a1db9a5d 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -31,6 +31,7 @@
#include "src/game/object_list_processor.h"
#include "src/game/behavior_actions.h"
#include "src/game/mario_misc.h"
+#include "src/pc/utils/misc.h"
#include "src/game/level_update.h"
@@ -11717,6 +11718,19 @@ int smlua_func_vec3s_to_vec3f(lua_State* L) {
}
*/
+ ////////////
+ // misc.h //
+////////////
+
+int smlua_func_update_all_mario_stars(UNUSED lua_State* L) {
+ if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
+
+
+ update_all_mario_stars();
+
+ return 1;
+}
+
//////////////////////
// network_player.h //
//////////////////////
@@ -16154,6 +16168,15 @@ int smlua_func_save_file_clear_flags(lua_State* L) {
return 1;
}
+int smlua_func_save_file_erase_current_backup_save(UNUSED lua_State* L) {
+ if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
+
+
+ save_file_erase_current_backup_save();
+
+ return 1;
+}
+
int smlua_func_save_file_get_cap_pos(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
@@ -16256,11 +16279,13 @@ int smlua_func_save_file_get_total_star_count(lua_State* L) {
return 1;
}
-int smlua_func_save_file_reload(UNUSED lua_State* L) {
- if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
+int smlua_func_save_file_reload(lua_State* L) {
+ if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
+ u8 load_all = smlua_to_integer(L, 1);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'save_file_reload'"); return 0; }
- save_file_reload();
+ save_file_reload(load_all);
return 1;
}
@@ -19177,6 +19202,9 @@ void smlua_bind_functions_autogen(void) {
//smlua_bind_function(L, "vec3s_sum", smlua_func_vec3s_sum); <--- UNIMPLEMENTED
//smlua_bind_function(L, "vec3s_to_vec3f", smlua_func_vec3s_to_vec3f); <--- UNIMPLEMENTED
+ // misc.h
+ smlua_bind_function(L, "update_all_mario_stars", smlua_func_update_all_mario_stars);
+
// network_player.h
smlua_bind_function(L, "get_network_player_from_area", smlua_func_get_network_player_from_area);
smlua_bind_function(L, "get_network_player_from_level", smlua_func_get_network_player_from_level);
@@ -19519,6 +19547,7 @@ void smlua_bind_functions_autogen(void) {
// save_file.h
smlua_bind_function(L, "save_file_clear_flags", smlua_func_save_file_clear_flags);
+ smlua_bind_function(L, "save_file_erase_current_backup_save", smlua_func_save_file_erase_current_backup_save);
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);
diff --git a/src/pc/network/network.c b/src/pc/network/network.c
index c29624ec..3b3d776a 100644
--- a/src/pc/network/network.c
+++ b/src/pc/network/network.c
@@ -529,6 +529,8 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup) {
extern void save_file_load_all(UNUSED u8 reload);
save_file_load_all(TRUE);
+ extern void save_file_set_using_backup_slot(bool usingBackupSlot);
+ save_file_set_using_backup_slot(false);
extern s16 gMenuMode;
gMenuMode = -1;