|
| 1 | +using HarmonyLib; |
| 2 | +using Multiplayer.API; |
| 3 | +using RimWorld; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Reflection; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using Verse; |
| 11 | + |
| 12 | +namespace Multiplayer.Client.Patches |
| 13 | +{ |
| 14 | + [HarmonyPatch] |
| 15 | + public static class PlanGetGizmosPatch |
| 16 | + { |
| 17 | + static IEnumerable<MethodBase> TargetMethods() |
| 18 | + { |
| 19 | + Type planType = AccessTools.TypeByName("Verse.Plan+<>c__DisplayClass45_0"); |
| 20 | + yield return AccessTools.Method(planType, "<GetGizmos>b__1"); |
| 21 | + } |
| 22 | + |
| 23 | + static bool Prefix(object __instance) |
| 24 | + { |
| 25 | + if (Multiplayer.Client == null) return true; |
| 26 | + |
| 27 | + Plan plan = (Plan)AccessTools.Field(__instance.GetType(), "<>4__this").GetValue(__instance); |
| 28 | + ColorDef color = (ColorDef)AccessTools.Field(__instance.GetType(), "newCol").GetValue(__instance); |
| 29 | + |
| 30 | + SyncSetPlanColor(plan, color); |
| 31 | + return false; |
| 32 | + } |
| 33 | + |
| 34 | + [SyncMethod] |
| 35 | + public static void SyncSetPlanColor(Plan plan, ColorDef color) |
| 36 | + { |
| 37 | + plan.Color = color; |
| 38 | + AccessTools.Method(typeof(Plan), "CheckContiguous").Invoke(plan, null); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + [HarmonyPatch(typeof(Designator_Plan_Copy), nameof(Designator_Plan_Copy.DesignateSingleCell))] |
| 43 | + public static class PlanCopySingleCellPatch |
| 44 | + { |
| 45 | + static bool Prefix(Designator_Plan_Copy __instance, IntVec3 c) |
| 46 | + { |
| 47 | + if (Multiplayer.Client == null) return true; |
| 48 | + |
| 49 | + SyncDesignateSingleCell(__instance, __instance.cells, __instance.colorDef); |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + [SyncMethod] |
| 54 | + public static void SyncDesignateSingleCell(Designator_Plan_Add designator, List<IntVec3> cells, ColorDef colorDef) |
| 55 | + { |
| 56 | + designator.colorDef = colorDef; |
| 57 | + designator.PlanCells(cells); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + [HarmonyPatch(typeof(Designator_Plan_CopySelectionPaste), nameof(Designator_Plan_CopySelectionPaste.DesignateSingleCell))] |
| 62 | + public static class PlanCopySelectionPasteSingleCellPatch |
| 63 | + { |
| 64 | + static bool Prefix(Designator_Plan_CopySelectionPaste __instance, IntVec3 c) |
| 65 | + { |
| 66 | + if (Multiplayer.Client == null) return true; |
| 67 | + |
| 68 | + foreach (ColorDef color in __instance.colors) |
| 69 | + SyncDesignateSingleCell(__instance, __instance.GetCurrentCells(c, color).ToList(), color); |
| 70 | + |
| 71 | + return false; |
| 72 | + } |
| 73 | + |
| 74 | + [SyncMethod] |
| 75 | + public static void SyncDesignateSingleCell(Designator_Plan_CopySelectionPaste designator, List<IntVec3> cells, ColorDef colorDef) |
| 76 | + { |
| 77 | + designator.SelectedPlan = null; |
| 78 | + designator.colorDef = colorDef; |
| 79 | + designator.PlanCells(cells); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments