From 16aa75ca93fe7a57422aea8c7eda416b213873ce Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 29 Mar 2022 21:12:42 -0700 Subject: [PATCH] Fix compile errors / run autogen --- autogen/lua_definitions/functions.lua | 25 ++++++++ autogen/lua_definitions/structs.lua | 2 + docs/lua/functions.md | 84 +++++++++++++++++++++++++++ docs/lua/structs.md | 2 + src/game/mario_actions_cutscene.c | 13 +++-- src/pc/lua/smlua_cobject_autogen.c | 46 ++++++++------- src/pc/lua/smlua_functions_autogen.c | 49 +++++++++++++--- 7 files changed, 186 insertions(+), 35 deletions(-) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 9660bfcd..489f44a0 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -2142,6 +2142,12 @@ function is_player_active(m) -- ... end +--- @param m MarioState +--- @return integer +function is_player_in_local_area(m) + -- ... +end + --- @param obj Object --- @param x number --- @param y number @@ -2642,6 +2648,14 @@ function random_mod_offset(base, step, mod) -- ... end +--- @param threshold number +--- @param distanceToPlayer Pointer_integer +--- @param angleToPlayer Pointer_integer +--- @return nil +function treat_far_home_as_mario(threshold, distanceToPlayer, angleToPlayer) + -- ... +end + --- @param x0 integer --- @param x1 integer --- @return integer @@ -3475,6 +3489,11 @@ function enable_time_stop() -- ... end +--- @return nil +function enable_time_stop_if_alone() + -- ... +end + --- @return nil function enable_time_stop_including_mario() -- ... @@ -3912,6 +3931,12 @@ function set_time_stop_flags(flags) -- ... end +--- @param flags integer +--- @return nil +function set_time_stop_flags_if_alone(flags) + -- ... +end + --- @param x integer --- @return integer function signum_positive(x) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index 17982f40..562c6a3e 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -31,6 +31,7 @@ --- @field public instantWarps InstantWarp --- @field public localAreaTimer integer --- @field public macroObjects Pointer_integer +--- @field public macroObjectsAltered Pointer_integer --- @field public musicParam integer --- @field public musicParam2 integer --- @field public objectSpawnInfos SpawnInfo @@ -1326,6 +1327,7 @@ --- @field public prevObj Object --- @field public respawnInfoType integer --- @field public unused1 integer +--- @field public usingObj Object --- @class ObjectHitbox --- @field public damageOrCoinValue integer diff --git a/docs/lua/functions.md b/docs/lua/functions.md index fc59ca4f..684218e5 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -399,6 +399,7 @@ - [is_nearest_mario_state_to_object](#is_nearest_mario_state_to_object) - [is_nearest_player_to_object](#is_nearest_player_to_object) - [is_player_active](#is_player_active) + - [is_player_in_local_area](#is_player_in_local_area) - [is_point_close_to_object](#is_point_close_to_object) - [is_point_within_radius_of_mario](#is_point_within_radius_of_mario) - [nearest_mario_state_to_object](#nearest_mario_state_to_object) @@ -472,6 +473,7 @@ - [platform_on_track_update_pos_or_spawn_ball](#platform_on_track_update_pos_or_spawn_ball) - [random_linear_offset](#random_linear_offset) - [random_mod_offset](#random_mod_offset) + - [treat_far_home_as_mario](#treat_far_home_as_mario)
@@ -614,6 +616,7 @@ - [dist_between_object_and_point](#dist_between_object_and_point) - [dist_between_objects](#dist_between_objects) - [enable_time_stop](#enable_time_stop) + - [enable_time_stop_if_alone](#enable_time_stop_if_alone) - [enable_time_stop_including_mario](#enable_time_stop_including_mario) - [find_unimportant_object](#find_unimportant_object) - [geo_offset_klepto_debug](#geo_offset_klepto_debug) @@ -676,6 +679,7 @@ - [random_f32_around_zero](#random_f32_around_zero) - [set_mario_interact_hoot_if_in_range](#set_mario_interact_hoot_if_in_range) - [set_time_stop_flags](#set_time_stop_flags) + - [set_time_stop_flags_if_alone](#set_time_stop_flags_if_alone) - [signum_positive](#signum_positive) - [spawn_base_star_with_no_lvl_exit](#spawn_base_star_with_no_lvl_exit) - [spawn_mist_particles](#spawn_mist_particles) @@ -7447,6 +7451,26 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [is_player_in_local_area](#is_player_in_local_area) + +### Lua Example +`local integerValue = is_player_in_local_area(m)` + +### Parameters +| Field | Type | +| ----- | ---- | +| m | [MarioState](structs.md#MarioState) | + +### Returns +- `integer` + +### C Prototype +`u8 is_player_in_local_area(struct MarioState* m);` + +[:arrow_up_small:](#) + +
+ ## [is_point_close_to_object](#is_point_close_to_object) ### Lua Example @@ -8908,6 +8932,28 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [treat_far_home_as_mario](#treat_far_home_as_mario) + +### Lua Example +`treat_far_home_as_mario(threshold, distanceToPlayer, angleToPlayer)` + +### Parameters +| Field | Type | +| ----- | ---- | +| threshold | `number` | +| distanceToPlayer | `Pointer` <`integer`> | +| angleToPlayer | `Pointer` <`integer`> | + +### Returns +- None + +### C Prototype +`void treat_far_home_as_mario(f32 threshold, s32* distanceToPlayer, s32* angleToPlayer);` + +[:arrow_up_small:](#) + +
+ --- # functions from object_helpers.c @@ -11619,6 +11665,24 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [enable_time_stop_if_alone](#enable_time_stop_if_alone) + +### Lua Example +`enable_time_stop_if_alone()` + +### Parameters +- None + +### Returns +- None + +### C Prototype +`void enable_time_stop_if_alone(void);` + +[:arrow_up_small:](#) + +
+ ## [enable_time_stop_including_mario](#enable_time_stop_including_mario) ### Lua Example @@ -12921,6 +12985,26 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [set_time_stop_flags_if_alone](#set_time_stop_flags_if_alone) + +### Lua Example +`set_time_stop_flags_if_alone(flags)` + +### Parameters +| Field | Type | +| ----- | ---- | +| flags | `integer` | + +### Returns +- None + +### C Prototype +`void set_time_stop_flags_if_alone(s32 flags);` + +[:arrow_up_small:](#) + +
+ ## [signum_positive](#signum_positive) ### Lua Example diff --git a/docs/lua/structs.md b/docs/lua/structs.md index ed133695..2ec5afea 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -113,6 +113,7 @@ | instantWarps | [InstantWarp](structs.md#InstantWarp) | | | localAreaTimer | `integer` | read-only | | macroObjects | `Pointer` <`integer`> | read-only | +| macroObjectsAltered | `Pointer` <`integer`> | read-only | | musicParam | `integer` | | | musicParam2 | `integer` | | | objectSpawnInfos | [SpawnInfo](structs.md#SpawnInfo) | | @@ -878,6 +879,7 @@ | prevObj | [Object](structs.md#Object) | | | respawnInfoType | `integer` | | | unused1 | `integer` | | +| usingObj | [Object](structs.md#Object) | | ### Object-Independent Data Fields | Field | Type | Access | diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index aa4bb46e..71805393 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -508,7 +508,7 @@ s32 act_reading_automatic_dialog(struct MarioState *m) { if (m->actionState == 9) { // only show dialog for local player if (m == &gMarioStates[0]) { - actionArg = m->actionArg; + u32 actionArg = m->actionArg; if (GET_HIGH_U16_OF_32(actionArg) == 0) { create_dialog_box(GET_LOW_U16_OF_32(actionArg)); } else { @@ -1428,13 +1428,14 @@ s32 act_bbh_enter_spin(struct MarioState *m) { switch (m->actionState) { case 0: - f32 floorDist = 512.0f - (m->pos[1] - m->floorHeight); - m->vel[1] = floorDist > 0 ? sqrtf(4.0f * floorDist + 1.0f) - 1.0f : 2.0f; + { + f32 floorDist = 512.0f - (m->pos[1] - m->floorHeight); + m->vel[1] = floorDist > 0 ? sqrtf(4.0f * floorDist + 1.0f) - 1.0f : 2.0f; - m->actionState = 1; - m->actionTimer = 100; + m->actionState = 1; + m->actionTimer = 100; + } // fall through - case 1: m->faceAngle[1] = atan2s(cageDZ, cageDX); mario_set_forward_vel(m, forwardVel); diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index a443628d..8ae05fc7 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -46,28 +46,29 @@ static struct LuaObjectField sAnimationFields[LUA_ANIMATION_FIELD_COUNT] = { { "values", LVT_S16_P, offsetof(struct Animation, values), true, LOT_POINTER }, }; -#define LUA_AREA_FIELD_COUNT 14 +#define LUA_AREA_FIELD_COUNT 15 static struct LuaObjectField sAreaFields[LUA_AREA_FIELD_COUNT] = { -// { "cachedBehaviors", LOT_???, offsetof(struct Area, cachedBehaviors), false, LOT_??? }, <--- UNIMPLEMENTED -// { "cachedPositions", LOT_???, offsetof(struct Area, cachedPositions), false, LOT_??? }, <--- UNIMPLEMENTED - { "camera", LVT_COBJECT_P, offsetof(struct Area, camera), false, LOT_CAMERA }, -// { "dialog", LOT_???, offsetof(struct Area, dialog), false, LOT_??? }, <--- UNIMPLEMENTED - { "flags", LVT_S8, offsetof(struct Area, flags), false, LOT_NONE }, - { "index", LVT_S8, offsetof(struct Area, index), false, LOT_NONE }, - { "instantWarps", LVT_COBJECT_P, offsetof(struct Area, instantWarps), false, LOT_INSTANTWARP }, - { "localAreaTimer", LVT_U32, offsetof(struct Area, localAreaTimer), true, LOT_NONE }, - { "macroObjects", LVT_S16_P, offsetof(struct Area, macroObjects), true, LOT_POINTER }, - { "musicParam", LVT_U16, offsetof(struct Area, musicParam), false, LOT_NONE }, - { "musicParam2", LVT_U16, offsetof(struct Area, musicParam2), false, LOT_NONE }, - { "objectSpawnInfos", LVT_COBJECT_P, offsetof(struct Area, objectSpawnInfos), false, LOT_SPAWNINFO }, - { "paintingWarpNodes", LVT_COBJECT_P, offsetof(struct Area, paintingWarpNodes), false, LOT_WARPNODE }, - { "surfaceRooms", LVT_S8_P, offsetof(struct Area, surfaceRooms), true, LOT_POINTER }, - { "terrainData", LVT_S16_P, offsetof(struct Area, terrainData), true, LOT_POINTER }, - { "terrainType", LVT_U16, offsetof(struct Area, terrainType), false, LOT_NONE }, -// { "unk04", LVT_COBJECT_P, offsetof(struct Area, unk04), false, LOT_??? }, <--- UNIMPLEMENTED -// { "unused28", LVT_COBJECT_P, offsetof(struct Area, unused28), false, LOT_??? }, <--- UNIMPLEMENTED - { "warpNodes", LVT_COBJECT_P, offsetof(struct Area, warpNodes), false, LOT_OBJECTWARPNODE }, -// { "whirlpools", LOT_???, offsetof(struct Area, whirlpools), false, LOT_??? }, <--- UNIMPLEMENTED +// { "cachedBehaviors", LOT_???, offsetof(struct Area, cachedBehaviors), false, LOT_??? }, <--- UNIMPLEMENTED +// { "cachedPositions", LOT_???, offsetof(struct Area, cachedPositions), false, LOT_??? }, <--- UNIMPLEMENTED + { "camera", LVT_COBJECT_P, offsetof(struct Area, camera), false, LOT_CAMERA }, +// { "dialog", LOT_???, offsetof(struct Area, dialog), false, LOT_??? }, <--- UNIMPLEMENTED + { "flags", LVT_S8, offsetof(struct Area, flags), false, LOT_NONE }, + { "index", LVT_S8, offsetof(struct Area, index), false, LOT_NONE }, + { "instantWarps", LVT_COBJECT_P, offsetof(struct Area, instantWarps), false, LOT_INSTANTWARP }, + { "localAreaTimer", LVT_U32, offsetof(struct Area, localAreaTimer), true, LOT_NONE }, + { "macroObjects", LVT_S16_P, offsetof(struct Area, macroObjects), true, LOT_POINTER }, + { "macroObjectsAltered", LVT_U8_P, offsetof(struct Area, macroObjectsAltered), true, LOT_POINTER }, + { "musicParam", LVT_U16, offsetof(struct Area, musicParam), false, LOT_NONE }, + { "musicParam2", LVT_U16, offsetof(struct Area, musicParam2), false, LOT_NONE }, + { "objectSpawnInfos", LVT_COBJECT_P, offsetof(struct Area, objectSpawnInfos), false, LOT_SPAWNINFO }, + { "paintingWarpNodes", LVT_COBJECT_P, offsetof(struct Area, paintingWarpNodes), false, LOT_WARPNODE }, + { "surfaceRooms", LVT_S8_P, offsetof(struct Area, surfaceRooms), true, LOT_POINTER }, + { "terrainData", LVT_S16_P, offsetof(struct Area, terrainData), true, LOT_POINTER }, + { "terrainType", LVT_U16, offsetof(struct Area, terrainType), false, LOT_NONE }, +// { "unk04", LVT_COBJECT_P, offsetof(struct Area, unk04), false, LOT_??? }, <--- UNIMPLEMENTED +// { "unused28", LVT_COBJECT_P, offsetof(struct Area, unused28), false, LOT_??? }, <--- UNIMPLEMENTED + { "warpNodes", LVT_COBJECT_P, offsetof(struct Area, warpNodes), false, LOT_OBJECTWARPNODE }, +// { "whirlpools", LOT_???, offsetof(struct Area, whirlpools), false, LOT_??? }, <--- UNIMPLEMENTED }; #define LUA_BULLY_COLLISION_DATA_FIELD_COUNT 6 @@ -681,7 +682,7 @@ static struct LuaObjectField sNetworkPlayerFields[LUA_NETWORK_PLAYER_FIELD_COUNT { "type", LVT_U8, offsetof(struct NetworkPlayer, type), true, LOT_NONE }, }; -#define LUA_OBJECT_FIELD_COUNT 751 +#define LUA_OBJECT_FIELD_COUNT 752 static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = { { "activeFlags", LVT_S16, offsetof(struct Object, activeFlags), false, LOT_NONE }, { "areaTimer", LVT_U32, offsetof(struct Object, areaTimer), false, LOT_NONE }, @@ -1446,6 +1447,7 @@ static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = { { "respawnInfoType", LVT_S16, offsetof(struct Object, respawnInfoType), false, LOT_NONE }, // { "transform", LVT_???, offsetof(struct Object, transform), false, LOT_??? }, <--- UNIMPLEMENTED { "unused1", LVT_U32, offsetof(struct Object, unused1), false, LOT_NONE }, + { "usingObj", LVT_COBJECT_P, offsetof(struct Object, usingObj), false, LOT_OBJECT }, }; #define LUA_OBJECT_HITBOX_FIELD_COUNT 9 diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 046d94b1..6994fee0 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -33,7 +33,7 @@ int smlua_func_get_behavior_from_id(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } - s32 id = smlua_to_integer(L, 1); + int id = smlua_to_integer(L, 1); if (!gSmLuaConvertSuccess) { return 0; } smlua_push_pointer(L, LVT_BEHAVIORSCRIPT_P, (void*)get_behavior_from_id(id)); @@ -4936,6 +4936,18 @@ int smlua_func_is_player_active(lua_State* L) { return 1; } +int smlua_func_is_player_in_local_area(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 1)) { return 0; } + + struct MarioState* m = (struct MarioState*)smlua_to_cobject(L, 1, LOT_MARIOSTATE); + if (!gSmLuaConvertSuccess) { return 0; } + + extern u8 is_player_in_local_area(struct MarioState* m); + lua_pushinteger(L, is_player_in_local_area(m)); + + return 1; +} + int smlua_func_is_point_close_to_object(lua_State* L) { if(!smlua_functions_valid_param_count(L, 5)) { return 0; } @@ -5950,23 +5962,21 @@ int smlua_func_random_mod_offset(lua_State* L) { return 1; } -/* int smlua_func_treat_far_home_as_mario(lua_State* L) { if(!smlua_functions_valid_param_count(L, 3)) { return 0; } f32 threshold = smlua_to_number(L, 1); if (!gSmLuaConvertSuccess) { return 0; } -// int* distanceToPlayer = (int*)smlua_to_cobject(L, 2, LOT_???); <--- UNIMPLEMENTED + s32* distanceToPlayer = (s32*)smlua_to_cpointer(L, 2, LVT_S32_P); if (!gSmLuaConvertSuccess) { return 0; } -// int* angleToPlayer = (int*)smlua_to_cobject(L, 3, LOT_???); <--- UNIMPLEMENTED + s32* angleToPlayer = (s32*)smlua_to_cpointer(L, 3, LVT_S32_P); if (!gSmLuaConvertSuccess) { return 0; } - extern void treat_far_home_as_mario(f32 threshold, int* distanceToPlayer, int* angleToPlayer); + extern void treat_far_home_as_mario(f32 threshold, s32* distanceToPlayer, s32* angleToPlayer); treat_far_home_as_mario(threshold, distanceToPlayer, angleToPlayer); return 1; } -*/ ////////////////////// // object_helpers.c // @@ -7656,6 +7666,16 @@ int smlua_func_enable_time_stop(UNUSED lua_State* L) { return 1; } +int smlua_func_enable_time_stop_if_alone(UNUSED lua_State* L) { + if(!smlua_functions_valid_param_count(L, 0)) { return 0; } + + + extern void enable_time_stop_if_alone(void); + enable_time_stop_if_alone(); + + return 1; +} + int smlua_func_enable_time_stop_including_mario(UNUSED lua_State* L) { if(!smlua_functions_valid_param_count(L, 0)) { return 0; } @@ -8760,6 +8780,18 @@ int smlua_func_set_time_stop_flags(lua_State* L) { return 1; } +int smlua_func_set_time_stop_flags_if_alone(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 1)) { return 0; } + + s32 flags = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { return 0; } + + extern void set_time_stop_flags_if_alone(s32 flags); + set_time_stop_flags_if_alone(flags); + + return 1; +} + int smlua_func_signum_positive(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } @@ -10297,6 +10329,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "is_nearest_mario_state_to_object", smlua_func_is_nearest_mario_state_to_object); smlua_bind_function(L, "is_nearest_player_to_object", smlua_func_is_nearest_player_to_object); smlua_bind_function(L, "is_player_active", smlua_func_is_player_active); + smlua_bind_function(L, "is_player_in_local_area", smlua_func_is_player_in_local_area); smlua_bind_function(L, "is_point_close_to_object", smlua_func_is_point_close_to_object); smlua_bind_function(L, "is_point_within_radius_of_mario", smlua_func_is_point_within_radius_of_mario); smlua_bind_function(L, "nearest_mario_state_to_object", smlua_func_nearest_mario_state_to_object); @@ -10368,7 +10401,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "platform_on_track_update_pos_or_spawn_ball", smlua_func_platform_on_track_update_pos_or_spawn_ball); smlua_bind_function(L, "random_linear_offset", smlua_func_random_linear_offset); smlua_bind_function(L, "random_mod_offset", smlua_func_random_mod_offset); - //smlua_bind_function(L, "treat_far_home_as_mario", smlua_func_treat_far_home_as_mario); <--- UNIMPLEMENTED + smlua_bind_function(L, "treat_far_home_as_mario", smlua_func_treat_far_home_as_mario); // object_helpers.c smlua_bind_function(L, "abs_angle_diff", smlua_func_abs_angle_diff); @@ -10510,6 +10543,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "dist_between_object_and_point", smlua_func_dist_between_object_and_point); smlua_bind_function(L, "dist_between_objects", smlua_func_dist_between_objects); smlua_bind_function(L, "enable_time_stop", smlua_func_enable_time_stop); + smlua_bind_function(L, "enable_time_stop_if_alone", smlua_func_enable_time_stop_if_alone); smlua_bind_function(L, "enable_time_stop_including_mario", smlua_func_enable_time_stop_including_mario); smlua_bind_function(L, "find_unimportant_object", smlua_func_find_unimportant_object); smlua_bind_function(L, "geo_offset_klepto_debug", smlua_func_geo_offset_klepto_debug); @@ -10583,6 +10617,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "random_f32_around_zero", smlua_func_random_f32_around_zero); smlua_bind_function(L, "set_mario_interact_hoot_if_in_range", smlua_func_set_mario_interact_hoot_if_in_range); smlua_bind_function(L, "set_time_stop_flags", smlua_func_set_time_stop_flags); + smlua_bind_function(L, "set_time_stop_flags_if_alone", smlua_func_set_time_stop_flags_if_alone); smlua_bind_function(L, "signum_positive", smlua_func_signum_positive); smlua_bind_function(L, "spawn_base_star_with_no_lvl_exit", smlua_func_spawn_base_star_with_no_lvl_exit); smlua_bind_function(L, "spawn_mist_particles", smlua_func_spawn_mist_particles);