From 62eeb01b4b72fcd07bc9365dbb96cda395b5211b Mon Sep 17 00:00:00 2001 From: Sunk <69110309+Sunketchupm@users.noreply.github.com> Date: Fri, 20 Oct 2023 12:10:43 -0400 Subject: [PATCH] Fix stars not respawning + other syncing fixes (#460) * Force secret stars to respawn Hacky fix for sure. I'll need to see how to deal with this in a better way. * Improve star syncing All stars now respawn (hopefully) and the red coin star no longer repeatedly respawns. Also forced oSyncDeath for other objects. * Remove leftover include * (Probably) improve star syncing It'll still spam packets but at least it'll only spam packets to people who are able to receive them * Revert "(Probably) improve star syncing" This reverts commit 86ff2c5451cff0a06e8c3410b2815e12b414f264. * Weird sync No idea why this works but it does. At least no fields have to be synced over, as far as I can tell. --- src/game/behaviors/sparkle_spawn_star.inc.c | 5 +++++ src/game/behaviors/spawn_star.inc.c | 11 +++++++++-- src/game/obj_behaviors_2.c | 4 ++-- src/pc/network/packets/packet_object.c | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/game/behaviors/sparkle_spawn_star.inc.c b/src/game/behaviors/sparkle_spawn_star.inc.c index 396b325f..3c14a494 100644 --- a/src/game/behaviors/sparkle_spawn_star.inc.c +++ b/src/game/behaviors/sparkle_spawn_star.inc.c @@ -80,6 +80,10 @@ void slow_star_rotation(void) { } void bhv_spawned_star_loop(void) { + if (!sync_object_is_initialized(o->oSyncID)) { + sync_object_init(o, SYNC_DISTANCE_ONLY_EVENTS); + } + if (o->oAction == 0) { // All of these are for checking if we spawned the star, If // we didn't. We don't need the time stop. @@ -140,6 +144,7 @@ void bhv_spawned_star_loop(void) { } else { set_sparkle_spawn_star_hitbox(); slow_star_rotation(); + network_send_object(o); } cur_obj_move_using_fvel_and_gravity(); o->oFaceAngleYaw += o->oAngleVelYaw; diff --git a/src/game/behaviors/spawn_star.inc.c b/src/game/behaviors/spawn_star.inc.c index 9bda024d..0ddcbb1e 100644 --- a/src/game/behaviors/spawn_star.inc.c +++ b/src/game/behaviors/spawn_star.inc.c @@ -106,6 +106,10 @@ void bhv_star_spawn_init(void) { } void bhv_star_spawn_loop(void) { + if (!sync_object_is_initialized(o->oSyncID)) { + sync_object_init(o, SYNC_DISTANCE_ONLY_EVENTS); + } + switch (o->oAction) { case 0: o->oFaceAngleYaw += 0x1000; @@ -148,6 +152,7 @@ void bhv_star_spawn_loop(void) { case 3: o->oFaceAngleYaw += 0x800; + cur_obj_become_tangible(); if (o->oTimer == 20) { gMarioStates[0].freeze = 0; gObjCutsceneDone = TRUE; @@ -159,6 +164,8 @@ void bhv_star_spawn_loop(void) { mark_obj_for_deletion(o); o->oInteractStatus = 0; } + + network_send_object(o); break; } spawn_star_number(); @@ -321,7 +328,7 @@ void bhv_hidden_red_coin_star_loop(void) { break; case 1: - if (o->oTimer == 3) { + if (o->oTimer > 2) { struct Object *obj = spawn_red_coin_cutscene_star(o->oPosX, o->oPosY, o->oPosZ); if (obj != NULL) { if (o->oHiddenStarLastInteractedObject == &gMarioStates[0]) { @@ -331,7 +338,7 @@ void bhv_hidden_red_coin_star_loop(void) { } spawn_mist_particles(); } - network_send_object(o); + o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } break; } diff --git a/src/game/obj_behaviors_2.c b/src/game/obj_behaviors_2.c index 602a7674..c54363e6 100644 --- a/src/game/obj_behaviors_2.c +++ b/src/game/obj_behaviors_2.c @@ -812,7 +812,7 @@ void obj_act_knockback(UNUSED f32 baseScale) { //! Dies immediately if above lava if ((o->oMoveFlags & (OBJ_MOVE_MASK_ON_GROUND | OBJ_MOVE_MASK_IN_WATER | OBJ_MOVE_HIT_WALL | OBJ_MOVE_ABOVE_LAVA)) - || (o->oAction == OBJ_ACT_VERTICAL_KNOCKBACK && o->oTimer >= 9)) { + || (o->oAction == OBJ_ACT_VERTICAL_KNOCKBACK && o->oTimer >= 9) || o->oSyncDeath) { obj_die_if_health_non_positive(); } @@ -832,7 +832,7 @@ void obj_act_squished(f32 baseScale) { if (approach_f32_ptr(&o->header.gfx.scale[1], targetScaleY, baseScale * 0.14f)) { o->header.gfx.scale[0] = o->header.gfx.scale[2] = baseScale * 2.0f - o->header.gfx.scale[1]; - if (o->oTimer >= 16) { + if (o->oTimer >= 16 || o->oSyncDeath) { obj_die_if_health_non_positive(); } } diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index 3178c8ee..8f8ead86 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -419,6 +419,7 @@ void network_receive_object(struct Packet* p) { // deactivated if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { + o->oSyncDeath = 1; // Force oSyncDeath if deactivated sync_object_forget(so->id); } else if (p->reliable) { // remember packet