Skip to content

Commit af25612

Browse files
authored
Merge pull request #542 from starfi5h/pr-fixPR536
Fix UpdateDirtyMeshes error, ILS desync
2 parents 05b6b4f + 88b7cb0 commit af25612

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

NebulaNetwork/PacketProcessors/Planet/FactoryDataProcessor.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,13 @@ public override void ProcessPacket(FactoryData packet, NebulaConnection conn)
2222

2323
PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);
2424
Multiplayer.Session.Planets.PendingFactories.Add(packet.PlanetId, packet.BinaryData);
25+
Multiplayer.Session.Planets.PendingTerrainData.Add(packet.PlanetId, packet.TerrainModData);
2526
Log.Info($"Parsing {packet.BinaryData.Length} bytes of data for factory {planet.name} (ID: {planet.id})");
2627

2728
lock (PlanetModelingManager.fctPlanetReqList)
2829
{
2930
PlanetModelingManager.fctPlanetReqList.Enqueue(planet);
3031
}
31-
32-
// Apply terrian changes, code from PlanetFactory.FlattenTerrainReform()
33-
planet.data.modData = packet.TerrainModData;
34-
for (int i = 0; i < planet.dirtyFlags.Length; i++)
35-
{
36-
planet.dirtyFlags[i] = true;
37-
}
38-
planet.landPercentDirty = true;
39-
planet.UpdateDirtyMeshes();
4032
}
4133
}
4234
}

NebulaPatcher/Patches/Dynamic/GalacticTransport_Patch.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ public static void SetForNewGame_Postfix()
1919

2020
[HarmonyPrefix]
2121
[HarmonyPatch(nameof(GalacticTransport.AddStationComponent))]
22-
public static bool AddStationComponent_Prefix()
22+
public static bool AddStationComponent_Prefix(StationComponent station)
2323
{
24-
// We will let host decide the value of gid, so client only add when the packet arrives
25-
return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.Ships.PatchLockILS;
24+
if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsClient && station.gid == 0)
25+
{
26+
// When client build a new station (gid == 0), we will let host decide the value of gid
27+
// ILS will be added when ILSAddStationComponent from host arrived
28+
return false;
29+
}
30+
return true;
2631
}
2732

2833
[HarmonyPrefix]

NebulaPatcher/Patches/Dynamic/GameData_Patch.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using NebulaModel.Packets.Players;
77
using NebulaPatcher.Patches.Transpilers;
88
using NebulaWorld;
9-
using System.Collections.Generic;
9+
using System;
1010
using UnityEngine;
1111

1212
namespace NebulaPatcher.Patches.Dynamic
@@ -141,6 +141,27 @@ public static bool OnActivePlanetFactoryLoaded_Prefix(GameData __instance, Plane
141141
Log.Info($"OnActivePlanetLoaded: Resume PacketProcessor");
142142
}
143143

144+
// Get the recieved bytes from the remote server that we will import
145+
if (Multiplayer.Session.Planets.PendingTerrainData.TryGetValue(planet.id, out byte[] terrainBytes))
146+
{
147+
// Apply terrian changes, code from PlanetFactory.FlattenTerrainReform()
148+
planet.data.modData = terrainBytes;
149+
for (int i = 0; i < planet.dirtyFlags.Length; i++)
150+
{
151+
planet.dirtyFlags[i] = true;
152+
}
153+
planet.landPercentDirty = true;
154+
try
155+
{
156+
planet.UpdateDirtyMeshes();
157+
}
158+
catch (Exception e)
159+
{
160+
Log.Error(e);
161+
}
162+
Multiplayer.Session.Planets.PendingTerrainData.Remove(planet.id);
163+
}
164+
144165
NebulaModAPI.OnPlanetLoadFinished?.Invoke(planet.id);
145166
}
146167

NebulaWorld/Planet/PlanetManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ namespace NebulaWorld.Planet
77
public class PlanetManager : IDisposable
88
{
99
public Dictionary<int, byte[]> PendingFactories { get; private set; }
10+
public Dictionary<int, byte[]> PendingTerrainData { get; private set; }
1011

1112
public readonly ToggleSwitch IsIncomingRequest = new ToggleSwitch();
1213

1314
public PlanetManager()
1415
{
1516
PendingFactories = new Dictionary<int, byte[]>();
17+
PendingTerrainData = new Dictionary<int, byte[]>();
1618
}
1719

1820
public void Dispose()
1921
{
2022
PendingFactories = null;
23+
PendingTerrainData = null;
2124
}
2225
}
2326
}

0 commit comments

Comments
 (0)