From d6ead264edc1812f89af0d99cbd9fa7571360426 Mon Sep 17 00:00:00 2001 From: Boondorl Date: Wed, 30 Jul 2025 19:35:24 -0400 Subject: [PATCH] Fixed +playerclass not being respected when new players join a save --- src/d_net.cpp | 3 +++ src/g_level.cpp | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/d_net.cpp b/src/d_net.cpp index abd0dc5fb..89b585561 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -1867,6 +1867,9 @@ void Net_ReadGameInfo(TArrayView& stream) Args->AppendArg(load); } } + + // Reset this immediately so any further RNG calls the engine has to make will be synced. + FRandom::StaticClearRandom(); } // Connects players to each other if needed. diff --git a/src/g_level.cpp b/src/g_level.cpp index 11d06c844..8cac0c179 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -549,6 +549,19 @@ static void InitPlayerClasses () } } +// Account for additional players joining from a save file. +static void UpdatePlayerClass(int i) +{ + if (!savegamerestore || !playeringame[i]) + return; + + SinglePlayerClass[i] = players[i].userinfo.GetPlayerClassNum(); + if (SinglePlayerClass[i] < 0) + SinglePlayerClass[i] = (pr_classchoice()) % PlayerClasses.Size(); + players[i].cls = nullptr; + players[i].CurrentPlayerClass = SinglePlayerClass[i]; +} + //========================================================================== // // @@ -2018,7 +2031,7 @@ void G_WriteVisited(FSerializer &arc) } // Store player classes to be used when spawning a random class - if (multiplayer) + if (!multiplayer || !deathmatch) { arc.Array("randomclasses", SinglePlayerClass, MAXPLAYERS); } @@ -2102,7 +2115,10 @@ void G_ReadVisited(FSerializer &arc) for (unsigned int i = 0; i < MAXPLAYERS; ++i) { FStringf key("%d", i); - arc(key.GetChars(), players[i].cls); + if (!arc.HasKey(key.GetChars())) + UpdatePlayerClass(i); + else + arc(key.GetChars(), players[i].cls); } arc.EndObject(); }