Fix crash in tox_box_move()

This commit is contained in:
MysterD 2023-11-08 12:34:55 -08:00
parent 301448f78a
commit c27ed37c7e
7 changed files with 26 additions and 106 deletions

View File

@ -100,7 +100,7 @@ override_disallowed_functions = {
"src/game/sound_init.h": [ "_loop_", "thread4_", "set_sound_mode" ],
"src/pc/network/network_utils.h": [ "network_get_player_text_color[^_]" ],
"src/pc/network/network_player.h": [ "_init", "_connected[^_]", "_shutdown", "_disconnected", "_update", "construct_player_popup" ],
"src/game/object_helpers.c": [ "spawn_obj", "^bhv_", "abs[fi]", "^bit_shift", "_debug$", "^stub_", "_set_model" ],
"src/game/object_helpers.c": [ "spawn_obj", "^bhv_", "abs[fi]", "^bit_shift", "_debug$", "^stub_", "_set_model", "cur_obj_set_direction_table", "cur_obj_progress_direction_table" ],
"src/game/obj_behaviors.c": [ "debug_" ],
"src/game/obj_behaviors_2.c": [ "wiggler_jumped_on_attack_handler", "huge_goomba_weakly_attacked" ],
"src/game/spawn_sound.c": [ "spawner" ],

View File

@ -6953,11 +6953,6 @@ function cur_obj_outside_home_square(halfLength)
-- ...
end
--- @return integer
function cur_obj_progress_direction_table()
-- ...
end
--- @param radius number
--- @return nil
function cur_obj_push_mario_away(radius)
@ -7034,12 +7029,6 @@ function cur_obj_set_billboard_if_vanilla_cam()
-- ...
end
--- @param a0 Pointer_integer
--- @return integer
function cur_obj_set_direction_table(a0)
-- ...
end
--- @return nil
function cur_obj_set_face_angle_to_move_angle()
-- ...

View File

@ -3577,24 +3577,6 @@
<br />
## [cur_obj_progress_direction_table](#cur_obj_progress_direction_table)
### Lua Example
`local integerValue = cur_obj_progress_direction_table()`
### Parameters
- None
### Returns
- `integer`
### C Prototype
`s32 cur_obj_progress_direction_table(void);`
[:arrow_up_small:](#)
<br />
## [cur_obj_push_mario_away](#cur_obj_push_mario_away)
### Lua Example
@ -3846,26 +3828,6 @@
<br />
## [cur_obj_set_direction_table](#cur_obj_set_direction_table)
### Lua Example
`local integerValue = cur_obj_set_direction_table(a0)`
### Parameters
| Field | Type |
| ----- | ---- |
| a0 | `Pointer` <`integer`> |
### Returns
- `integer`
### C Prototype
`s32 cur_obj_set_direction_table(s8 *a0);`
[:arrow_up_small:](#)
<br />
## [cur_obj_set_face_angle_to_move_angle](#cur_obj_set_face_angle_to_move_angle)
### Lua Example

View File

@ -1316,7 +1316,6 @@
- [cur_obj_nearest_object_with_behavior](functions-4.md#cur_obj_nearest_object_with_behavior)
- [cur_obj_outside_home_rectangle](functions-4.md#cur_obj_outside_home_rectangle)
- [cur_obj_outside_home_square](functions-4.md#cur_obj_outside_home_square)
- [cur_obj_progress_direction_table](functions-4.md#cur_obj_progress_direction_table)
- [cur_obj_push_mario_away](functions-4.md#cur_obj_push_mario_away)
- [cur_obj_push_mario_away_from_cylinder](functions-4.md#cur_obj_push_mario_away_from_cylinder)
- [cur_obj_reflect_move_angle_off_wall](functions-4.md#cur_obj_reflect_move_angle_off_wall)
@ -1330,7 +1329,6 @@
- [cur_obj_scale_over_time](functions-4.md#cur_obj_scale_over_time)
- [cur_obj_set_behavior](functions-4.md#cur_obj_set_behavior)
- [cur_obj_set_billboard_if_vanilla_cam](functions-4.md#cur_obj_set_billboard_if_vanilla_cam)
- [cur_obj_set_direction_table](functions-4.md#cur_obj_set_direction_table)
- [cur_obj_set_face_angle_to_move_angle](functions-4.md#cur_obj_set_face_angle_to_move_angle)
- [cur_obj_set_hitbox_and_die_if_attacked](functions-4.md#cur_obj_set_hitbox_and_die_if_attacked)
- [cur_obj_set_hitbox_radius_and_height](functions-4.md#cur_obj_set_hitbox_radius_and_height)

View File

@ -1,12 +1,12 @@
// tox_box.c.inc
s8 D_8032F8F0[] = { 4, 1, 4, 1, 6, 1, 6, 1, 5, 1, 5, 1, 6, 1, 6, 1, 5, 1, 2, 4, 1, 4, 1, 4, 1, 2,
5, 1, 5, 1, 7, 1, 7, 1, 4, 1, 4, 1, 7, 1, 7, 1, 5, 1, 5, 1, 5, 1, 2, 4, 1, -1 };
s8 D_8032F924[] = { 4, 1, 4, 1, 7, 1, 7, 1, 7, 1, 2, 6, 1, 6, 1, 6, 1, 5,
1, 5, 1, 6, 1, 5, 1, 5, 1, 2, 4, 1, 4, 1, 7, 1, -1 };
s8 D_8032F948[] = { 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 2, 5, 1, 5, 1, 5, 1, 5,
1, 5, 1, 7, 1, 2, 6, 1, 6, 1, 5, 1, 2, 4, 1, 7, 1, -1 };
s8 *D_8032F96C[] = { D_8032F8F0, D_8032F924, D_8032F948 };
s8 sToxBoxDirectionTable0[] = { 4, 1, 4, 1, 6, 1, 6, 1, 5, 1, 5, 1, 6, 1, 6, 1, 5, 1, 2, 4, 1, 4, 1, 4, 1, 2,
5, 1, 5, 1, 7, 1, 7, 1, 4, 1, 4, 1, 7, 1, 7, 1, 5, 1, 5, 1, 5, 1, 2, 4, 1, -1 };
s8 sToxBoxDirectionTable1[] = { 4, 1, 4, 1, 7, 1, 7, 1, 7, 1, 2, 6, 1, 6, 1, 6, 1, 5,
1, 5, 1, 6, 1, 5, 1, 5, 1, 2, 4, 1, 4, 1, 7, 1, -1 };
s8 sToxBoxDirectionTable2[] = { 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 2, 5, 1, 5, 1, 5, 1, 5,
1, 5, 1, 7, 1, 2, 6, 1, 6, 1, 5, 1, 2, 4, 1, 7, 1, -1 };
s8 *sToxBoxDirectionTables[] = { sToxBoxDirectionTable0, sToxBoxDirectionTable1, sToxBoxDirectionTable2 };
void tox_box_shake_screen(void) {
if (o && o->oDistanceToMario < 3000.0f)
@ -71,9 +71,8 @@ void tox_box_act_3(void) {
void tox_box_act_0(void) {
if (!o) { return; }
if (!BHV_ARR_CHECK(D_8032F96C, o->oBehParams2ndByte, s8*)) { return; }
s8 *sp1C = D_8032F96C[o->oBehParams2ndByte];
o->oAction = cur_obj_set_direction_table(sp1C);
if (!BHV_ARR_CHECK(sToxBoxDirectionTables, o->oBehParams2ndByte, s8*)) { return; }
o->oAction = cur_obj_set_direction_table(sToxBoxDirectionTables[o->oBehParams2ndByte]);
}
void (*sToxBoxActions[])(void) = { tox_box_act_0, tox_box_act_1, tox_box_act_2, tox_box_act_3,

View File

@ -2716,20 +2716,28 @@ s32 cur_obj_set_direction_table(s8 *a0) {
s32 cur_obj_progress_direction_table(void) {
if (!o) { return 0; }
s8 spF;
s8 *sp8 = o->oToxBoxMovementPattern;
s32 sp4 = o->oToxBoxMovementStep + 1;
if (!sp8) { return 0; }
s8 ret;
s8 *table = o->oToxBoxMovementPattern;
s32 index = o->oToxBoxMovementStep + 1;
if (!table) { return 0; }
if (sp8[sp4] != -1) {
spF = sp8[sp4];
s32 tableLength = 0;
while (table[tableLength] != -1 && tableLength < 50) {
tableLength++;
}
if (tableLength >= 50 || index >= tableLength) {
ret = table[0];
o->oToxBoxMovementStep = 0;
} else if (table[index] != -1) {
ret = table[index];
o->oToxBoxMovementStep++;
} else {
spF = sp8[0];
ret = table[0];
o->oToxBoxMovementStep = 0;
}
return spF;
return ret;
}
void stub_obj_helpers_3(UNUSED s32 sp0, UNUSED s32 sp4) {

View File

@ -23246,22 +23246,6 @@ int smlua_func_cur_obj_outside_home_square(lua_State* L) {
return 1;
}
int smlua_func_cur_obj_progress_direction_table(UNUSED lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 0) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "cur_obj_progress_direction_table", 0, top);
return 0;
}
extern s32 cur_obj_progress_direction_table(void);
lua_pushinteger(L, cur_obj_progress_direction_table());
return 1;
}
int smlua_func_cur_obj_push_mario_away(lua_State* L) {
if (L == NULL) { return 0; }
@ -23492,24 +23476,6 @@ int smlua_func_cur_obj_set_billboard_if_vanilla_cam(UNUSED lua_State* L) {
return 1;
}
int smlua_func_cur_obj_set_direction_table(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 1) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "cur_obj_set_direction_table", 1, top);
return 0;
}
s8 * a0 = (s8 *)smlua_to_cpointer(L, 1, LVT_S8_P);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "cur_obj_set_direction_table"); return 0; }
extern s32 cur_obj_set_direction_table(s8 *a0);
lua_pushinteger(L, cur_obj_set_direction_table(a0));
return 1;
}
int smlua_func_cur_obj_set_face_angle_to_move_angle(UNUSED lua_State* L) {
if (L == NULL) { return 0; }
@ -32253,7 +32219,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "cur_obj_nearest_object_with_behavior", smlua_func_cur_obj_nearest_object_with_behavior);
smlua_bind_function(L, "cur_obj_outside_home_rectangle", smlua_func_cur_obj_outside_home_rectangle);
smlua_bind_function(L, "cur_obj_outside_home_square", smlua_func_cur_obj_outside_home_square);
smlua_bind_function(L, "cur_obj_progress_direction_table", smlua_func_cur_obj_progress_direction_table);
smlua_bind_function(L, "cur_obj_push_mario_away", smlua_func_cur_obj_push_mario_away);
smlua_bind_function(L, "cur_obj_push_mario_away_from_cylinder", smlua_func_cur_obj_push_mario_away_from_cylinder);
smlua_bind_function(L, "cur_obj_reflect_move_angle_off_wall", smlua_func_cur_obj_reflect_move_angle_off_wall);
@ -32267,7 +32232,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "cur_obj_scale_over_time", smlua_func_cur_obj_scale_over_time);
smlua_bind_function(L, "cur_obj_set_behavior", smlua_func_cur_obj_set_behavior);
smlua_bind_function(L, "cur_obj_set_billboard_if_vanilla_cam", smlua_func_cur_obj_set_billboard_if_vanilla_cam);
smlua_bind_function(L, "cur_obj_set_direction_table", smlua_func_cur_obj_set_direction_table);
smlua_bind_function(L, "cur_obj_set_face_angle_to_move_angle", smlua_func_cur_obj_set_face_angle_to_move_angle);
smlua_bind_function(L, "cur_obj_set_hitbox_and_die_if_attacked", smlua_func_cur_obj_set_hitbox_and_die_if_attacked);
smlua_bind_function(L, "cur_obj_set_hitbox_radius_and_height", smlua_func_cur_obj_set_hitbox_radius_and_height);