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:
@@ -16,40 +16,28 @@ namespace KCM.Packets.Lobby
|
|||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
Main.helper.Log(GameState.inst.mainMenuMode.ToString());
|
Main.helper.Log("Starting multiplayer game...");
|
||||||
|
|
||||||
// Hide server lobby
|
|
||||||
Main.TransitionTo((MenuState)200);
|
|
||||||
|
|
||||||
// This is run when user clicks "accept" on choose your map screeen
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!LobbyManager.loadingSave)
|
// For multiplayer, we don't call MainMenuMode.StartGame() because:
|
||||||
{
|
// 1. Clients never go through the "Choose Your Map" screen
|
||||||
SpeedControlUI.inst.SetSpeed(0);
|
// 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
|
SpeedControlUI.inst.SetSpeed(0);
|
||||||
{
|
|
||||||
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);
|
// Transition to playing mode
|
||||||
}
|
GameState.inst.SetNewMode(GameState.inst.playingMode);
|
||||||
else
|
|
||||||
{
|
SpeedControlUI.inst.SetSpeed(0);
|
||||||
LobbyManager.loadingSave = false;
|
|
||||||
GameState.inst.SetNewMode(GameState.inst.playingMode);
|
Main.helper.Log("Successfully started multiplayer game");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Handle exception here
|
Main.helper.Log("Error starting multiplayer game:");
|
||||||
Main.helper.Log(ex.Message.ToString());
|
Main.helper.Log(ex.Message.ToString());
|
||||||
Main.helper.Log(ex.ToString());
|
Main.helper.Log(ex.ToString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user