diff --git a/Source/Client/AsyncTime/AsyncTimeComp.cs b/Source/Client/AsyncTime/AsyncTimeComp.cs index 444d5cb59..59ba2dadd 100644 --- a/Source/Client/AsyncTime/AsyncTimeComp.cs +++ b/Source/Client/AsyncTime/AsyncTimeComp.cs @@ -385,6 +385,33 @@ bool SetState(Designator designator) Find.Selector.selected.Add(zone); } + if (designator is Designator_Plan_Add designatorPlanAdd) + { + designatorPlanAdd.colorDef = SyncSerialization.ReadSync(data); + designator = designatorPlanAdd; + } + + if (designator is Designator_Plan_Copy designatorPlanCopy) + { + designatorPlanCopy.cells.Clear(); + designatorPlanCopy.cells.AddRange(SyncSerialization.ReadSync>(data)); + designator = designatorPlanCopy; + } + + if (designator is Designator_Plan_CopySelectionPaste pasteDesignator) + { + pasteDesignator.indices = SyncSerialization.ReadSync(data); + pasteDesignator.rotation = SyncSerialization.ReadSync(data); + + pasteDesignator.grid.Clear(); + pasteDesignator.grid.AddRange(SyncSerialization.ReadSync>(data)); + + pasteDesignator.colors.Clear(); + pasteDesignator.colors.AddRange(SyncSerialization.ReadSync>(data)); + + designator = pasteDesignator; + } + return true; } @@ -406,8 +433,6 @@ void RestoreState() if (mode == DesignatorMode.SingleCell) { IntVec3 cell = SyncSerialization.ReadSync(data); - if (designator is Designator_Plan_Add addDesignator) - addDesignator.colorDef = SyncSerialization.ReadSync(data); designator.DesignateSingleCell(cell); designator.Finalize(true); @@ -415,8 +440,6 @@ void RestoreState() else if (mode == DesignatorMode.MultiCell) { IntVec3[] cells = SyncSerialization.ReadSync(data); - if (designator is Designator_Plan_Add addDesignator) - addDesignator.colorDef = SyncSerialization.ReadSync(data); designator.DesignateMultiCell(cells); } diff --git a/Source/Client/MultiplayerStatic.cs b/Source/Client/MultiplayerStatic.cs index 0eed8d81e..cf02c6e44 100644 --- a/Source/Client/MultiplayerStatic.cs +++ b/Source/Client/MultiplayerStatic.cs @@ -325,7 +325,9 @@ void TryPatch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod po }; foreach (Type t in typeof(Designator).AllSubtypesAndSelf() - .Except(typeof(Designator_MechControlGroup))) // Opens float menu, sync that instead + // Designator_MechControlGroup Opens float menu, sync that instead + // Designator_Plan_CopySelection creates the placement gizmo, this shouldn't be synced + .Except([typeof(Designator_MechControlGroup), typeof(Designator_Plan_CopySelection)])) { foreach ((string m, Type[] args) in designatorMethods) { diff --git a/Source/Client/Patches/Designators.cs b/Source/Client/Patches/Designators.cs index 65b1fff6d..646c3e3b7 100644 --- a/Source/Client/Patches/Designators.cs +++ b/Source/Client/Patches/Designators.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using Multiplayer.Client.Util; using Multiplayer.Common; using RimWorld; using System; @@ -25,7 +26,6 @@ public static class DesignatorPatches public static bool DesignateSingleCell(Designator __instance, IntVec3 __0) { if (!Multiplayer.InInterface) return true; - if (__instance is Designator_Plan_Copy or Designator_Plan_CopySelection or Designator_Plan_CopySelectionPaste) return true; Designator designator = __instance; @@ -36,9 +36,6 @@ public static bool DesignateSingleCell(Designator __instance, IntVec3 __0) WriteData(writer, DesignatorMode.SingleCell, designator); SyncSerialization.WriteSync(writer, __0); - if (__instance is Designator_Plan_Add addDesignator) - SyncSerialization.WriteSync(writer, addDesignator.colorDef); - SendSyncCommand(map.uniqueID, writer); Multiplayer.WriterLog.AddCurrentNode(writer); @@ -124,6 +121,20 @@ private static void WriteData(ByteWriter data, DesignatorMode mode, Designator d if (designator is Designator_Zone) SyncSerialization.WriteSync(data, Find.Selector.SelectedZone); + + if (designator is Designator_Plan_Add addDesignator) + SyncSerialization.WriteSync(data, addDesignator.colorDef); + + if (designator is Designator_Plan_Copy copyDesignator) + SyncSerialization.WriteSync(data, copyDesignator.cells); + + if (designator is Designator_Plan_CopySelectionPaste pasteDesignator) + { + SyncSerialization.WriteSync(data, pasteDesignator.indices); + SyncSerialization.WriteSync(data, pasteDesignator.rotation); + SyncSerialization.WriteSync(data, pasteDesignator.grid); + SyncSerialization.WriteSync(data, pasteDesignator.colors); + } } } diff --git a/Source/Client/Patches/Plans.cs b/Source/Client/Patches/Plans.cs index 0441ee4c9..42f2f89fa 100644 --- a/Source/Client/Patches/Plans.cs +++ b/Source/Client/Patches/Plans.cs @@ -3,10 +3,7 @@ using RimWorld; using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Verse; namespace Multiplayer.Client.Patches @@ -38,45 +35,4 @@ public static void SyncSetPlanColor(Plan plan, ColorDef color) AccessTools.Method(typeof(Plan), "CheckContiguous").Invoke(plan, null); } } - - [HarmonyPatch(typeof(Designator_Plan_Copy), nameof(Designator_Plan_Copy.DesignateSingleCell))] - public static class PlanCopySingleCellPatch - { - static bool Prefix(Designator_Plan_Copy __instance, IntVec3 c) - { - if (Multiplayer.Client == null) return true; - - SyncDesignateSingleCell(__instance, __instance.cells, __instance.colorDef); - return false; - } - - [SyncMethod] - public static void SyncDesignateSingleCell(Designator_Plan_Add designator, List cells, ColorDef colorDef) - { - designator.colorDef = colorDef; - designator.PlanCells(cells); - } - } - - [HarmonyPatch(typeof(Designator_Plan_CopySelectionPaste), nameof(Designator_Plan_CopySelectionPaste.DesignateSingleCell))] - public static class PlanCopySelectionPasteSingleCellPatch - { - static bool Prefix(Designator_Plan_CopySelectionPaste __instance, IntVec3 c) - { - if (Multiplayer.Client == null) return true; - - foreach (ColorDef color in __instance.colors) - SyncDesignateSingleCell(__instance, __instance.GetCurrentCells(c, color).ToList(), color); - - return false; - } - - [SyncMethod] - public static void SyncDesignateSingleCell(Designator_Plan_CopySelectionPaste designator, List cells, ColorDef colorDef) - { - designator.SelectedPlan = null; - designator.colorDef = colorDef; - designator.PlanCells(cells); - } - } } diff --git a/Source/Client/Syncing/Dict/SyncDictMisc.cs b/Source/Client/Syncing/Dict/SyncDictMisc.cs index 681bfb095..21e346664 100644 --- a/Source/Client/Syncing/Dict/SyncDictMisc.cs +++ b/Source/Client/Syncing/Dict/SyncDictMisc.cs @@ -184,6 +184,14 @@ public static class SyncDictMisc sync.Bind(ref vec.z); } }, + { + (ByteWriter data, CellIndices cellIndices) => + { + data.WriteInt32(cellIndices.sizeX); + data.WriteInt32(cellIndices.sizeZ); + }, + (ByteReader data) => new CellIndices(data.ReadInt32(), data.ReadInt32()) + } #endregion }; }