Fixed bounds checks in save_file_is_cannon_unlocked()

This commit is contained in:
MysterD 2023-05-20 20:07:17 -07:00
parent 9a065ffced
commit 1dd70283da
5 changed files with 51 additions and 2 deletions

View File

@ -7897,6 +7897,13 @@ function save_file_get_total_star_count(fileIndex, minCourse, maxCourse)
-- ...
end
--- @param fileIndex integer
--- @param courseIndex integer
--- @return integer
function save_file_is_cannon_unlocked(fileIndex, courseIndex)
-- ...
end
--- @param load_all integer
--- @return nil
function save_file_reload(load_all)

View File

@ -6705,6 +6705,27 @@
<br />
## [save_file_is_cannon_unlocked](#save_file_is_cannon_unlocked)
### Lua Example
`local integerValue = save_file_is_cannon_unlocked(fileIndex, courseIndex)`
### Parameters
| Field | Type |
| ----- | ---- |
| fileIndex | `integer` |
| courseIndex | `integer` |
### Returns
- `integer`
### C Prototype
`s32 save_file_is_cannon_unlocked(s32 fileIndex, s32 courseIndex);`
[:arrow_up_small:](#)
<br />
## [save_file_reload](#save_file_reload)
### Lua Example

View File

@ -1461,6 +1461,7 @@
- [save_file_get_sound_mode](functions-4.md#save_file_get_sound_mode)
- [save_file_get_star_flags](functions-4.md#save_file_get_star_flags)
- [save_file_get_total_star_count](functions-4.md#save_file_get_total_star_count)
- [save_file_is_cannon_unlocked](functions-4.md#save_file_is_cannon_unlocked)
- [save_file_reload](functions-4.md#save_file_reload)
- [save_file_set_flags](functions-4.md#save_file_set_flags)
- [save_file_set_star_flags](functions-4.md#save_file_set_star_flags)

View File

@ -697,9 +697,9 @@ s32 save_file_get_course_coin_score(s32 fileIndex, s32 courseIndex) {
* Return TRUE if the cannon is unlocked in the current course.
*/
s32 save_file_is_cannon_unlocked(s32 fileIndex, s32 courseIndex) {
if (INVALID_FILE_INDEX(gCurrSaveFileNum - 1)) { return 0; }
if (INVALID_FILE_INDEX(fileIndex)) { return 0; }
if (INVALID_SRC_SLOT(gSaveFileUsingBackupSlot)) { return 0; }
if (INVALID_COURSE_STAR_INDEX(gCurrCourseNum)) { return 0; }
if (INVALID_COURSE_STAR_INDEX(courseIndex)) { return 0; }
return (gSaveBuffer.files[fileIndex][gSaveFileUsingBackupSlot].courseStars[courseIndex] & 0x80) != 0;
}

View File

@ -26466,6 +26466,25 @@ int smlua_func_save_file_get_total_star_count(lua_State* L) {
return 1;
}
int smlua_func_save_file_is_cannon_unlocked(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", "save_file_is_cannon_unlocked", 2, top);
return 0;
}
s32 fileIndex = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "save_file_is_cannon_unlocked"); return 0; }
s32 courseIndex = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "save_file_is_cannon_unlocked"); return 0; }
lua_pushinteger(L, save_file_is_cannon_unlocked(fileIndex, courseIndex));
return 1;
}
int smlua_func_save_file_reload(lua_State* L) {
if (L == NULL) { return 0; }
@ -31442,6 +31461,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_is_cannon_unlocked", smlua_func_save_file_is_cannon_unlocked);
smlua_bind_function(L, "save_file_reload", smlua_func_save_file_reload);
smlua_bind_function(L, "save_file_set_flags", smlua_func_save_file_set_flags);
smlua_bind_function(L, "save_file_set_star_flags", smlua_func_save_file_set_star_flags);