From 89d2eb98534312350bbb1379434d90fbe779e2c7 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sun, 26 Mar 2023 21:35:04 -0700 Subject: [PATCH] Deterministically set the syncId of child objects of level objects --- src/game/area.c | 1 + src/pc/network/sync_object.c | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/game/area.c b/src/game/area.c index d416233c..0887a658 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -251,6 +251,7 @@ void load_area(s32 index) { if (gCurrentArea == NULL && gAreaData[index].unk04 != NULL) { gCurrentArea = &gAreaData[index]; gCurrentArea->localAreaTimer = 0; + gCurrentArea->nextSyncID = 10; gCurrAreaIndex = gCurrentArea->index; if (gCurrentArea->terrainData != NULL) { diff --git a/src/pc/network/sync_object.c b/src/pc/network/sync_object.c index aa8de6be..5940d997 100644 --- a/src/pc/network/sync_object.c +++ b/src/pc/network/sync_object.c @@ -374,14 +374,27 @@ bool sync_object_set_id(struct Object* o) { u32 syncId = o->oSyncID; if (syncId == 0) { if (!gNetworkAreaLoaded) { + // check if we should set our id based on our parent + if (o->parentObj != NULL && o->parentObj->oSyncID > 0 && (o->parentObj->oSyncID % 10) == 0) { + for (s32 i = 0; i < 10; i++) { + u32 tSyncId = o->parentObj->oSyncID + i; + struct SyncObject* so = sync_object_get(tSyncId); + if (so && so->o != NULL) { continue; } + syncId = tSyncId; + break; + } + } + // while loading, just fill in sync ids from 1 to SYNC_ID_BLOCK_SIZE - for (s32 i = 1; i < SYNC_ID_BLOCK_SIZE; i++) { - sNextSyncId++; - sNextSyncId = sNextSyncId % SYNC_ID_BLOCK_SIZE; - struct SyncObject* so = sync_object_get(sNextSyncId); - if (so && so->o != NULL) { continue; } - syncId = sNextSyncId; - break; + if (syncId == 0) { + for (s32 i = 1; i < SYNC_ID_BLOCK_SIZE; i++) { + sNextSyncId++; + sNextSyncId = sNextSyncId % SYNC_ID_BLOCK_SIZE; + struct SyncObject* so = sync_object_get(sNextSyncId); + if (so && so->o != NULL) { continue; } + syncId = sNextSyncId; + break; + } } } else { // no longer loading, require reserved id