Skip to content

Commit

Permalink
Fix desync by GameData.CreateDysonSphere
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Mar 22, 2024
1 parent 10a0027 commit 3ef47e4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ protected override void ProcessPacket(DysonSphereStatusPacket packet, NebulaConn
{
return;
}
// Replace some values set in DysonSphere.BeforeGameTick
dysonSphere.grossRadius = packet.GrossRadius;
dysonSphere.energyReqCurrentTick = packet.EnergyReqCurrentTick;
dysonSphere.energyGenCurrentTick = packet.EnergyGenCurrentTick;
dysonSphere.energyGenOriginalCurrentTick = (long)(dysonSphere.energyGenCurrentTick / dysonSphere.energyDFHivesDebuffCoef);
}
}
34 changes: 34 additions & 0 deletions NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,38 @@ private static void RefreshMissingMeshes()
Log.Debug("RefreshMissingMeshes");
}
}

[HarmonyPrefix]
[HarmonyPatch(nameof(GameData.CreateDysonSphere))]
public static bool CreateDysonSphere_Prefix(GameData __instance, int starIndex, ref DysonSphere __result)
{
if (!Multiplayer.IsActive || Multiplayer.Session.IsServer) return true;


if ((ulong)starIndex >= (ulong)((long)__instance.galaxy.starCount))
{
__result = null;
return false;
}
if (__instance.dysonSpheres[starIndex] != null)
{
__result = __instance.dysonSpheres[starIndex];
return false;
}

// Create a dummy dyson sphere and prevent sending packets
Multiplayer.Session.DysonSpheres.InBlueprint = true;
__instance.dysonSpheres[starIndex] = new DysonSphere();
__instance.dysonSpheres[starIndex].Init(__instance, __instance.galaxy.stars[starIndex]);
__instance.dysonSpheres[starIndex].ResetNew();
Multiplayer.Session.DysonSpheres.InBlueprint = false;

if (Multiplayer.Session.DysonSpheres.RequestingIndex == -1)
{
// If client is not requesting yet, request the target sphere from server
Multiplayer.Session.DysonSpheres.RequestDysonSphere(starIndex, false);
}
__result = __instance.dysonSpheres[starIndex];
return false;
}
}

0 comments on commit 3ef47e4

Please sign in to comment.