diff --git a/port/include/net/net.h b/port/include/net/net.h index e99179f63..ac9c87c73 100644 --- a/port/include/net/net.h +++ b/port/include/net/net.h @@ -103,6 +103,9 @@ extern s32 g_NetMode; extern u32 g_NetTick; extern u32 g_NetNextSyncId; +extern u64 g_NetRngSeeds[2]; +extern u32 g_NetRngLatch; + extern u32 g_NetInterpTicks; extern u32 g_NetServerPort; extern char g_NetLastJoinAddr[NET_MAX_ADDR + 1]; @@ -135,6 +138,8 @@ void netServerStageStart(void); void netServerStageEnd(void); void netServerKick(struct netclient *cl, const u32 reason); +void netClientSyncRng(void); + void netPlayersAllocate(void); void netSyncIdsAllocate(void); diff --git a/port/src/net/net.c b/port/src/net/net.c index 3aaf1a143..84a1a71f0 100644 --- a/port/src/net/net.c +++ b/port/src/net/net.c @@ -42,6 +42,9 @@ u32 g_NetNextSyncId = 1; s32 g_NetSimPacketLoss = 0; s32 g_NetDebugDraw = 0; +u64 g_NetRngSeeds[2]; +u32 g_NetRngLatch = 0; + s32 g_NetMaxClients = NET_MAX_CLIENTS; s32 g_NetNumClients = 0; struct netclient g_NetClients[NET_MAX_CLIENTS + 1]; // last is an extra temporary client @@ -605,6 +608,15 @@ static void netClientEvReceive(struct netclient *cl) } } +void netClientSyncRng(void) +{ + if (g_NetMode == NETMODE_CLIENT && g_NetRngLatch) { + g_NetRngLatch = 0; + g_RngSeed = g_NetRngSeeds[0]; + g_Rng2Seed = g_NetRngSeeds[1]; + } +} + void netStartFrame(void) { if (!g_NetMode) { diff --git a/port/src/net/netmsg.c b/port/src/net/netmsg.c index 890de37e6..df5ebe057 100644 --- a/port/src/net/netmsg.c +++ b/port/src/net/netmsg.c @@ -29,9 +29,6 @@ #include "net/netbuf.h" #include "net/netmsg.h" -extern u64 g_RngSeed; -extern u64 g_Rng2Seed; - /* utils */ static inline u32 netbufWriteRooms(struct netbuf *buf, const s16 *rooms, const s32 num) @@ -404,8 +401,9 @@ u32 netmsgSvcStageStartRead(struct netbuf *src, struct netclient *srccl) g_NetTick = netbufReadU32(src); - g_RngSeed = netbufReadU64(src); - g_Rng2Seed = netbufReadU64(src); + g_NetRngSeeds[0] = netbufReadU64(src); + g_NetRngSeeds[1] = netbufReadU64(src); + g_NetRngLatch = true; const u8 stagenum = netbufReadU8(src); diff --git a/src/game/lv.c b/src/game/lv.c index 4b6614847..988e5f760 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -324,8 +324,13 @@ void lvReset(s32 stagenum) s32 j; #ifndef PLATFORM_N64 - // if we're a server, signal to clients that the level is changing - netServerStageStart(); + if (g_NetMode == NETMODE_SERVER) { + // if we're a server, signal to clients that the level is changing + netServerStageStart(); + } else if (g_NetMode == NETMODE_CLIENT) { + // if we're a client, now is the time to apply the server's RNG seeds + netClientSyncRng(); + } #endif tilesReset(); diff --git a/src/include/data.h b/src/include/data.h index 47107df9f..0ccf08cbe 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -513,6 +513,8 @@ extern u8 g_ChrBioSlot; extern u8 g_HangarBioSlot; extern u8 g_DtSlot; extern u8 var80088bb4; +extern u64 g_RngSeed; +extern u64 g_Rng2Seed; extern struct vtxstoretype g_VtxstoreTypes[4]; extern struct menudialogdef g_FrWeaponListMenuDialog; extern struct menudialogdef g_FrTrainingInfoInGameMenuDialog;