Fix StartGame NullReferenceException in multiplayer

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 <noreply@anthropic.com>
This commit is contained in:
2025-12-14 20:52:44 +01:00
parent dbc0328c6f
commit fc467f4af8

View File

@@ -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());
}