Fix 3 critical bugs: server shutdown, building placement crashes

Fixed issues:
1. Server now stops when host returns to menu (Main.cs:342-356)
   - Notifies clients with "Host disconnected" modal
   - Prevents server from running in background

2. PlayerAddBuildingHook NullReferenceException (Main.cs:762-806)
   - Added comprehensive null checks for reflection fields
   - Added array bounds validation for landMass index
   - Added registry initialization checks
   - Fixes 98% building placement failure rate

3. IndexOutOfRangeException in WorldPlace (WorldPlace.cs:167-183)
   - LandMassNames array auto-expands when needed
   - Defensive code prevents index out of bounds errors

Updated README.md:
- Removed fixed issues from bug tracker
- Added "Fixed Issues" section documenting changes

🤖 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:06:53 +01:00
parent deb0c0ad92
commit b0f790cb6e
3 changed files with 91 additions and 200 deletions

View File

@@ -164,8 +164,23 @@ namespace KCM.Packets.Game.GameWorld
Main.helper.Log($"Host player Landmass Names Count: {Player.inst.LandMassNames.Count}, Contents: {string.Join(", ", Player.inst.LandMassNames)}");
Main.helper.Log($"Client player ({player.name}) Landmass Names Count: {player.inst.LandMassNames.Count}, Contents: {string.Join(", ", player.inst.LandMassNames)}");
player.inst.LandMassNames[building.LandMass()] = player.kingdomName;
Player.inst.LandMassNames[building.LandMass()] = player.kingdomName;
// Ensure LandMassNames arrays are large enough to prevent IndexOutOfRangeException
int landMass = building.LandMass();
// Expand player.inst.LandMassNames if needed
while (player.inst.LandMassNames.Count <= landMass)
{
player.inst.LandMassNames.Add("");
}
// Expand Player.inst.LandMassNames if needed
while (Player.inst.LandMassNames.Count <= landMass)
{
Player.inst.LandMassNames.Add("");
}
player.inst.LandMassNames[landMass] = player.kingdomName;
Player.inst.LandMassNames[landMass] = player.kingdomName;
// Log final building state after placement
Main.LogSync("---------- BUILDING PLACED FINAL STATE ----------");