From cbb7eb419c8f0dc653b84d5d77d75c44b96bee4f Mon Sep 17 00:00:00 2001 From: MysterD Date: Thu, 5 Aug 2021 00:22:03 -0700 Subject: [PATCH] Prevent level/area/object sync during credits sequence --- src/pc/network/packets/packet_change_area.c | 3 ++- src/pc/network/packets/packet_change_level.c | 3 ++- src/pc/network/packets/packet_object.c | 12 +++++++++++- src/pc/network/packets/packet_spawn_objects.c | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/pc/network/packets/packet_change_area.c b/src/pc/network/packets/packet_change_area.c index bde53c907..d871d9db5 100644 --- a/src/pc/network/packets/packet_change_area.c +++ b/src/pc/network/packets/packet_change_area.c @@ -17,7 +17,8 @@ static void player_changed_area(struct NetworkPlayer* np, s16 courseNum, s16 act // find a NetworkPlayer at that area struct NetworkPlayer* npLevelAreaMatch = get_network_player_from_area(courseNum, actNum, levelNum, areaIndex); - if (npLevelAreaMatch == NULL) { + bool inCredits = (np->currActNum == 99); + if (npLevelAreaMatch == NULL || inCredits) { // no NetworkPlayer in the level network_send_sync_valid(np); network_send_level_area_inform(np); diff --git a/src/pc/network/packets/packet_change_level.c b/src/pc/network/packets/packet_change_level.c index 44ccd8463..677784eab 100644 --- a/src/pc/network/packets/packet_change_level.c +++ b/src/pc/network/packets/packet_change_level.c @@ -20,7 +20,8 @@ static void player_changed_level(struct NetworkPlayer* np, s16 courseNum, s16 ac struct NetworkPlayer* npLevelMatch = get_network_player_from_level(courseNum, actNum, levelNum); struct NetworkPlayer* npAny = (npLevelAreaMatch == NULL) ? npLevelMatch : npLevelAreaMatch; - if (npAny == NULL) { + bool inCredits = (np->currActNum == 99); + if (npAny == NULL || inCredits) { // no NetworkPlayer in the level network_send_sync_valid(np); network_send_level_area_inform(np); diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index 2d368929e..1d52719ee 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -9,6 +9,7 @@ #include "src/game/memory.h" #include "src/game/object_helpers.h" #include "src/game/obj_behaviors.h" +#include "src/game/area.h" #include "pc/debuglog.h" #include "pc/utils/misc.h" @@ -40,6 +41,9 @@ static float player_distance(struct MarioState* marioState, struct Object* o) { } static bool should_own_object(struct SyncObject* so) { + // always own objects in credit sequence + if (gCurrActStarNum == 99) { return true; } + // check for override u8 shouldOverride = FALSE; u8 shouldOwn = FALSE; @@ -407,6 +411,8 @@ void network_send_object(struct Object* o) { } void network_send_object_reliability(struct Object* o, bool reliable) { + // prevent sending objects during credits sequence + if (gCurrActStarNum == 99) { return; } // sanity check SyncObject if (!network_sync_object_initialized(o)) { return; } u8 syncId = o->oSyncID; @@ -453,6 +459,9 @@ void network_send_object_reliability(struct Object* o, bool reliable) { } void network_receive_object(struct Packet* p) { + // prevent receiving objects during credits sequence + if (gCurrActStarNum == 99) { return; } + // read the header and sanity check the packet u8 fromLocalIndex = 0; struct SyncObject* so = packet_read_object_header(p, &fromLocalIndex); @@ -570,7 +579,8 @@ void network_update_objects(void) { if (timeSinceUpdate < updateRate) { continue; } // update! - if (network_player_any_connected()) { + bool inCredits = (gCurrActStarNum == 99); + if (network_player_any_connected() && !inCredits) { network_send_object(gSyncObjects[i].o); } } diff --git a/src/pc/network/packets/packet_spawn_objects.c b/src/pc/network/packets/packet_spawn_objects.c index 3b8544cfa..3c35d8bad 100644 --- a/src/pc/network/packets/packet_spawn_objects.c +++ b/src/pc/network/packets/packet_spawn_objects.c @@ -4,6 +4,7 @@ #include "object_fields.h" #include "object_constants.h" #include "src/game/object_helpers.h" +#include "src/game/area.h" #include "behavior_data.h" #include "behavior_table.h" //#define DISABLE_MODULE_LOG 1 @@ -47,7 +48,8 @@ void network_send_spawn_objects(struct Object* objects[], u32 models[], u8 objec void network_send_spawn_objects_to(u8 sendToLocalIndex, struct Object* objects[], u32 models[], u8 objectCount) { assert(objectCount < MAX_SPAWN_OBJECTS_PER_PACKET); - if (sendToLocalIndex == gNetworkPlayerLocal->localIndex) { return; } + // prevent sending spawn objects during credits + if (gCurrActStarNum == 99) { return; } struct Packet p; packet_init(&p, PACKET_SPAWN_OBJECTS, true, true); @@ -81,6 +83,8 @@ void network_send_spawn_objects_to(u8 sendToLocalIndex, struct Object* objects[] void network_receive_spawn_objects(struct Packet* p) { LOG_INFO("rx spawn objects"); + // prevent receiving spawn objects during credits + if (gCurrActStarNum == 99) { return; } u8 objectCount = 0; packet_read(p, &objectCount, sizeof(u8));