diff --git a/Main.cs b/Main.cs index 86dd41c..f8393c5 100644 --- a/Main.cs +++ b/Main.cs @@ -1660,9 +1660,10 @@ namespace KCM __instance.JobCustomMaxEnabledFlag = new bool[World.inst.NumLandMasses][]; for (int lm = 0; lm < World.inst.NumLandMasses; lm++) { - __instance.JobFilledAvailable[lm] = new int[38]; - __instance.JobCustomMaxEnabledFlag[lm] = new bool[38]; - for (int n = 0; n < 38; n++) + int numJobTypes = p.JobFilledAvailable.data[lm].GetLength(0); + __instance.JobFilledAvailable[lm] = new int[numJobTypes]; + __instance.JobCustomMaxEnabledFlag[lm] = new bool[numJobTypes]; + for (int n = 0; n < numJobTypes; n++) { __instance.JobFilledAvailable[lm][n] = p.JobFilledAvailable.data[lm][n, 1]; } diff --git a/Packets/Lobby/StartGame.cs b/Packets/Lobby/StartGame.cs index eefcfcf..823f9c2 100644 --- a/Packets/Lobby/StartGame.cs +++ b/Packets/Lobby/StartGame.cs @@ -57,7 +57,17 @@ namespace KCM.Packets.Lobby public override void HandlePacketClient() { - Start(); + if (!LobbyManager.loadingSave) + { + Start(); + } + else + { + // If loading a save, just ensure the game is in the correct UI state for loading. + // The actual game start will happen after save data is unpacked in SaveTransferPacket.HandlePacketClient(). + // This prevents MainMenuMode.StartGame() from being called prematurely and causing NullReferenceExceptions. + GameState.inst.SetNewMode(GameState.inst.playingMode); + } } public override void HandlePacketServer()