From dcc9090ac0fea21e96be9a3765d30027c9e1d59a Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Sat, 10 May 2025 13:17:09 +1000 Subject: [PATCH] rename Area's unk04 to root and fix lookup error --- autogen/convert_structs.py | 3 +-- autogen/lua_definitions/structs.lua | 2 +- docs/lua/structs.md | 2 +- src/engine/level_script.c | 4 ++-- src/game/area.c | 18 +++++++++--------- src/game/area.h | 2 +- src/pc/lua/smlua_cobject_autogen.c | 2 +- src/pc/lua/utils/smlua_level_utils.c | 2 +- src/pc/network/packets/packet_level_macro.c | 2 +- .../network/packets/packet_level_spawn_info.c | 2 +- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py index bcf772be4..d09e5613f 100644 --- a/autogen/convert_structs.py +++ b/autogen/convert_structs.py @@ -71,7 +71,6 @@ struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key); """ override_field_names = { - "Area": {"unk04": "root"} } override_field_types = { @@ -117,7 +116,7 @@ override_field_immutable = { "GlobalObjectAnimations": [ "*"], "SpawnParticlesInfo": [ "model" ], "MarioBodyState": [ "updateTorsoTime" ], - "Area": [ "localAreaTimer", "nextSyncID", "unk04", "objectSpawnInfos", "paintingWarpNodes", "warpNodes" ], + "Area": [ "localAreaTimer", "nextSyncID", "objectSpawnInfos", "paintingWarpNodes", "warpNodes" ], "Mod": [ "*" ], "ModFile": [ "*" ], "Painting": [ "id", "imageCount", "textureType", "textureWidth", "textureHeight" ], diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index 3fe65dc84..add7a2432 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -45,10 +45,10 @@ --- @field public numSecrets integer --- @field public objectSpawnInfos SpawnInfo --- @field public paintingWarpNodes WarpNode +--- @field public root GraphNodeRoot --- @field public surfaceRooms Pointer_integer --- @field public terrainData Pointer_integer --- @field public terrainType integer ---- @field public root GraphNodeRoot --- @field public warpNodes ObjectWarpNode --- @field public whirlpools Whirlpool[] diff --git a/docs/lua/structs.md b/docs/lua/structs.md index 740fab0e9..65ebaec11 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -191,10 +191,10 @@ | numSecrets | `integer` | | | objectSpawnInfos | [SpawnInfo](structs.md#SpawnInfo) | read-only | | paintingWarpNodes | [WarpNode](structs.md#WarpNode) | read-only | +| root | [GraphNodeRoot](structs.md#GraphNodeRoot) | | | surfaceRooms | `Pointer` <`integer`> | read-only | | terrainData | `Pointer` <`integer`> | read-only | | terrainType | `integer` | | -| root | [GraphNodeRoot](structs.md#GraphNodeRoot) | | | warpNodes | [ObjectWarpNode](structs.md#ObjectWarpNode) | read-only | | whirlpools | `Array` <`Whirlpool`> | | diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 106da957a..7d7129cbc 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -374,7 +374,7 @@ static void level_reset_globals(void) { // clear area's level pool pointers for (int i = 0; i < MAX_AREAS; i++) { - gAreas[i].unk04 = NULL; + gAreas[i].root = NULL; } // reset mariostate spawninfo pointers @@ -439,7 +439,7 @@ static void level_cmd_begin_area(void) { sCurrAreaIndex = areaIndex; screenArea->areaIndex = areaIndex; - gAreas[areaIndex].unk04 = screenArea; + gAreas[areaIndex].root = screenArea; gAreas[areaIndex].numRedCoins = 0; gAreas[areaIndex].numSecrets = 0; gAreas[areaIndex].nextSyncID = 10; diff --git a/src/game/area.c b/src/game/area.c index 7a8922029..a83cc3b2d 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -232,7 +232,7 @@ void clear_areas(void) { gAreaData[i].index = i; gAreaData[i].flags = 0; gAreaData[i].terrainType = 0; - gAreaData[i].unk04 = NULL; + gAreaData[i].root = NULL; gAreaData[i].terrainData = NULL; gAreaData[i].surfaceRooms = NULL; gAreaData[i].macroObjects = NULL; @@ -255,21 +255,21 @@ void clear_areas(void) { void clear_area_graph_nodes(void) { if (gCurrentArea != NULL) { - geo_call_global_function_nodes(&gCurrentArea->unk04->node, GEO_CONTEXT_AREA_UNLOAD); + geo_call_global_function_nodes(&gCurrentArea->root->node, GEO_CONTEXT_AREA_UNLOAD); gCurrentArea = NULL; gWarpTransition.isActive = FALSE; } for (s32 i = 0; i < MAX_AREAS; i++) { - if (gAreaData[i].unk04 != NULL) { - geo_call_global_function_nodes(&gAreaData[i].unk04->node, GEO_CONTEXT_AREA_INIT); - gAreaData[i].unk04 = NULL; + if (gAreaData[i].root != NULL) { + geo_call_global_function_nodes(&gAreaData[i].root->node, GEO_CONTEXT_AREA_INIT); + gAreaData[i].root = NULL; } } } void load_area(s32 index) { - if (gCurrentArea == NULL && gAreaData[index].unk04 != NULL) { + if (gCurrentArea == NULL && gAreaData[index].root != NULL) { gCurrentArea = &gAreaData[index]; gCurrentArea->localAreaTimer = 0; if (gCurrentArea->objectSpawnInfos) { @@ -287,7 +287,7 @@ void load_area(s32 index) { } load_obj_warp_nodes(); - geo_call_global_function_nodes(&gCurrentArea->unk04->node, GEO_CONTEXT_AREA_LOAD); + geo_call_global_function_nodes(&gCurrentArea->root->node, GEO_CONTEXT_AREA_LOAD); } } @@ -301,7 +301,7 @@ void unload_area(void) { sync_objects_clear(); if (gCurrentArea != NULL) { unload_objects_from_area(0, gCurrentArea->index); - geo_call_global_function_nodes(&gCurrentArea->unk04->node, GEO_CONTEXT_AREA_UNLOAD); + geo_call_global_function_nodes(&gCurrentArea->root->node, GEO_CONTEXT_AREA_UNLOAD); gCurrentArea->flags = 0; gCurrentArea = NULL; @@ -442,7 +442,7 @@ void play_transition_after_delay(s16 transType, s16 time, u8 red, u8 green, u8 b void render_game(void) { dynos_update_gfx(); if (gCurrentArea != NULL && !gWarpTransition.pauseRendering) { - geo_process_root(gCurrentArea->unk04, D_8032CE74, D_8032CE78, gFBSetColor); + geo_process_root(gCurrentArea->root, D_8032CE74, D_8032CE78, gFBSetColor); gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&D_8032CF00)); diff --git a/src/game/area.h b/src/game/area.h index c7243b1fe..0fe0b45c6 100644 --- a/src/game/area.h +++ b/src/game/area.h @@ -68,7 +68,7 @@ struct Area /*0x00*/ s8 index; /*0x01*/ s8 flags; // Only has 1 flag: 0x01 = Is this the active area? /*0x02*/ u16 terrainType; // default terrain of the level (set from level script cmd 0x31) - /*0x04*/ struct GraphNodeRoot *unk04; // geometry layout data + /*0x04*/ struct GraphNodeRoot *root; // geometry layout data /*0x08*/ s16 *terrainData; // collision data (set from level script cmd 0x2E) /*0x0C*/ s8 *surfaceRooms; // (set from level script cmd 0x2F) /*0x10*/ s16 *macroObjects; // Macro Objects Ptr (set from level script cmd 0x39) diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index 77b60409e..534ba39d2 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -183,10 +183,10 @@ static struct LuaObjectField sAreaFields[LUA_AREA_FIELD_COUNT] = { { "numSecrets", LVT_U8, offsetof(struct Area, numSecrets), false, LOT_NONE, 1, sizeof(u8) }, { "objectSpawnInfos", LVT_COBJECT_P, offsetof(struct Area, objectSpawnInfos), true, LOT_SPAWNINFO, 1, sizeof(struct SpawnInfo*) }, { "paintingWarpNodes", LVT_COBJECT_P, offsetof(struct Area, paintingWarpNodes), true, LOT_WARPNODE, 1, sizeof(struct WarpNode*) }, + { "root", LVT_COBJECT_P, offsetof(struct Area, root), false, LOT_GRAPHNODEROOT, 1, sizeof(struct GraphNodeRoot*) }, { "surfaceRooms", LVT_S8_P, offsetof(struct Area, surfaceRooms), true, LOT_POINTER, 1, sizeof(s8*) }, { "terrainData", LVT_S16_P, offsetof(struct Area, terrainData), true, LOT_POINTER, 1, sizeof(s16*) }, { "terrainType", LVT_U16, offsetof(struct Area, terrainType), false, LOT_NONE, 1, sizeof(u16) }, - { "root", LVT_COBJECT_P, offsetof(struct Area, unk04), false, LOT_GRAPHNODEROOT, 1, sizeof(struct GraphNodeRoot*) }, // { "unused28", LVT_COBJECT_P, offsetof(struct Area, unused28), false, LOT_???, 1, sizeof(struct UnusedArea28*) }, <--- UNIMPLEMENTED { "warpNodes", LVT_COBJECT_P, offsetof(struct Area, warpNodes), true, LOT_OBJECTWARPNODE, 1, sizeof(struct ObjectWarpNode*) }, { "whirlpools", LVT_COBJECT_P, offsetof(struct Area, whirlpools), false, LOT_WHIRLPOOL, 2, sizeof(struct Whirlpool*) }, diff --git a/src/pc/lua/utils/smlua_level_utils.c b/src/pc/lua/utils/smlua_level_utils.c index b4d430354..dfb2d1380 100644 --- a/src/pc/lua/utils/smlua_level_utils.c +++ b/src/pc/lua/utils/smlua_level_utils.c @@ -35,7 +35,7 @@ void smlua_level_util_reset(void) { } void smlua_level_util_change_area(s32 areaIndex) { - if (areaIndex >= MIN_AREA_INDEX && areaIndex < MAX_AREAS && gAreas[areaIndex].unk04 != NULL) { + if (areaIndex >= MIN_AREA_INDEX && areaIndex < MAX_AREAS && gAreas[areaIndex].root != NULL) { change_area(areaIndex); } } diff --git a/src/pc/network/packets/packet_level_macro.c b/src/pc/network/packets/packet_level_macro.c index dcba75923..3cae16a7a 100644 --- a/src/pc/network/packets/packet_level_macro.c +++ b/src/pc/network/packets/packet_level_macro.c @@ -30,7 +30,7 @@ static struct Object* get_object_matching_respawn_info(s16* respawnInfo) { static void network_send_level_macro_area(struct NetworkPlayer* destNp, u8 areaIndex) { // check that the area is active struct Area* area = &gAreaData[areaIndex]; - if (area->unk04 == NULL) { return; } + if (area->root == NULL) { return; } if (destNp == NULL || !destNp->connected) { LOG_ERROR("network_send_level_macro: dest np is invalid"); diff --git a/src/pc/network/packets/packet_level_spawn_info.c b/src/pc/network/packets/packet_level_spawn_info.c index 6b12e2c82..816be414b 100644 --- a/src/pc/network/packets/packet_level_spawn_info.c +++ b/src/pc/network/packets/packet_level_spawn_info.c @@ -28,7 +28,7 @@ static struct Object* get_object_matching_respawn_info(u32* respawnInfo) { static void network_send_level_spawn_info_area(struct NetworkPlayer* destNp, u8 areaIndex) { // check that the area is active struct Area* area = &gAreaData[areaIndex]; - if (area->unk04 == NULL) { return; } + if (area->root == NULL) { return; } if (destNp == NULL || !destNp->connected) { LOG_ERROR("network_send_level_spawn_info_area: dest np is invalid");