From 1c7451fcfc1c6188e901b475d7fb7a0a209beef6 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 11 Mar 2022 01:31:12 -0800 Subject: [PATCH] Prevent spawning objects from lua before the area is synchronized --- src/game/area.c | 2 +- src/pc/lua/utils/smlua_obj_utils.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/game/area.c b/src/game/area.c index f8979d85..e63135b1 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -146,7 +146,7 @@ void print_intro_text(void) { u32 get_mario_spawn_type(struct Object *o) { if (o == NULL) { return 0; } - + const BehaviorScript *behavior = virtual_to_segmented(0x13, o->behavior); for (s32 i = 0; i < 20; i++) { diff --git a/src/pc/lua/utils/smlua_obj_utils.c b/src/pc/lua/utils/smlua_obj_utils.c index 9bca2af9..73efa8d4 100644 --- a/src/pc/lua/utils/smlua_obj_utils.c +++ b/src/pc/lua/utils/smlua_obj_utils.c @@ -9,6 +9,9 @@ #include "pc/debuglog.h" static struct Object* spawn_object_internal(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z, LuaFunction objSetupFunction, bool doSync) { + // prevent spawning objects before area is synchronized + if (gNetworkPlayerLocal == NULL || !gNetworkPlayerLocal->currAreaSyncValid) { return NULL; } + const BehaviorScript* behavior = get_behavior_from_id(behaviorId); if (behavior == NULL) { LOG_ERROR("failed to find behavior %u", behaviorId);