From fc467f4af8762a41e8e3a882504b5c737e7eddf4 Mon Sep 17 00:00:00 2001 From: devbeni Date: Sun, 14 Dec 2025 20:52:44 +0100 Subject: [PATCH] Fix StartGame NullReferenceException in multiplayer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove MainMenuMode.StartGame() reflection call that expected "Choose Your Map" screen state. Clients never see this screen in multiplayer, causing null references. Now transitions directly to playing mode like save loading does. Fixes: NullReferenceException at MainMenuMode.StartGame() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- Packets/Lobby/StartGame.cs | 40 +++++++++++++------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/Packets/Lobby/StartGame.cs b/Packets/Lobby/StartGame.cs index eefcfcf..271f2ac 100644 --- a/Packets/Lobby/StartGame.cs +++ b/Packets/Lobby/StartGame.cs @@ -16,40 +16,28 @@ namespace KCM.Packets.Lobby public void Start() { - Main.helper.Log(GameState.inst.mainMenuMode.ToString()); - - // Hide server lobby - Main.TransitionTo((MenuState)200); - - // This is run when user clicks "accept" on choose your map screeen + Main.helper.Log("Starting multiplayer game..."); try { - if (!LobbyManager.loadingSave) - { - SpeedControlUI.inst.SetSpeed(0); + // For multiplayer, we don't call MainMenuMode.StartGame() because: + // 1. Clients never go through the "Choose Your Map" screen + // 2. MainMenuMode.StartGame() expects that screen's state to be initialized + // 3. Calling it causes NullReferenceException + // Instead, we transition directly to playing mode like when loading saves - try - { - typeof(MainMenuMode).GetMethod("StartGame", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(GameState.inst.mainMenuMode, null); - } - catch (Exception ex) - { - Main.helper.Log(ex.Message.ToString()); - Main.helper.Log(ex.ToString()); - } + SpeedControlUI.inst.SetSpeed(0); - SpeedControlUI.inst.SetSpeed(0); - } - else - { - LobbyManager.loadingSave = false; - GameState.inst.SetNewMode(GameState.inst.playingMode); - } + // Transition to playing mode + GameState.inst.SetNewMode(GameState.inst.playingMode); + + SpeedControlUI.inst.SetSpeed(0); + + Main.helper.Log("Successfully started multiplayer game"); } catch (Exception ex) { - // Handle exception here + Main.helper.Log("Error starting multiplayer game:"); Main.helper.Log(ex.Message.ToString()); Main.helper.Log(ex.ToString()); }