diff --git a/Source/Mods/VanillaExpandedFramework.cs b/Source/Mods/VanillaExpandedFramework.cs index 97a3672..2d54d43 100644 --- a/Source/Mods/VanillaExpandedFramework.cs +++ b/Source/Mods/VanillaExpandedFramework.cs @@ -995,8 +995,15 @@ private static IEnumerable ReplaceTickWithConditionalTick(IEnum #region Pipe System + // Deconstruct private static Type deconstructPipeDesignatorType; private static AccessTools.FieldRef deconstructPipeDesignatorNetDefField; + // Pipe net manager + private static Type pipeNetManagerType; + private static AccessTools.FieldRef pipeNetManagerPipeNetsListField; + // Pipe net + private static AccessTools.FieldRef pipeNetMapField; + private static AccessTools.FieldRef pipeNetDefField; private static void PatchPipeSystem() { @@ -1017,6 +1024,15 @@ private static void PatchPipeSystem() var type = deconstructPipeDesignatorType = AccessTools.TypeByName("PipeSystem.Designator_DeconstructPipe"); deconstructPipeDesignatorNetDefField = AccessTools.FieldRefAccess(type, "pipeNetDef"); MP.RegisterSyncWorker(SyncDeconstructPipeDesignator, type); + + // Pipe net + type = pipeNetManagerType = AccessTools.TypeByName("PipeSystem.PipeNetManager"); + pipeNetManagerPipeNetsListField = AccessTools.FieldRefAccess(type, "pipeNets"); + + type = AccessTools.TypeByName("PipeSystem.PipeNet"); + pipeNetMapField = AccessTools.FieldRefAccess(type, "map"); + pipeNetDefField = AccessTools.FieldRefAccess(type, "def"); + MP.RegisterSyncWorker(SyncPipeNet, type, true); } private static void SyncDeconstructPipeDesignator(SyncWorker sync, ref Designator_Deconstruct designator) @@ -1027,6 +1043,94 @@ private static void SyncDeconstructPipeDesignator(SyncWorker sync, ref Designato designator = (Designator_Deconstruct)Activator.CreateInstance(deconstructPipeDesignatorType, sync.Read()); } + private static void SyncPipeNet(SyncWorker sync, ref object pipeNet) + { + if (sync.isWriting) + { + // Sync null net as -1 + if (pipeNet == null) + { + sync.Write(-1); + return; + } + + // No map, can't get manager - log error and treat as null + var map = pipeNetMapField(pipeNet); + if (map == null) + { + Log.Error($"Trying to sync a PipeNet with a null map. PipeNet={pipeNet}"); + sync.Write(-1); + return; + } + + // No manager for map, shouldn't happen - log error and treat as null + var manager = map.GetComponent(pipeNetManagerType); + if (manager == null) + { + Log.Error($"Trying to sync a PipeNet with a map that doesn't have PipeNetManager. PipeNet={pipeNet}, Map={map}"); + sync.Write(-1); + return; + } + + var def = pipeNetDefField(pipeNet); + var list = pipeNetManagerPipeNetsListField(manager); + var index = -1; + var found = false; + + foreach (var currentPipeNet in list) + { + if (def == pipeNetDefField(currentPipeNet)) + { + index++; + if (pipeNet == currentPipeNet) + { + found = true; + break; + } + } + } + + if (!found) + { + // We did not find the pipe net - log error and treat as null + Log.Error($"Trying to sync a PipeNet, but it's not held by the manager. PipeNet={pipeNet}, map={map}, manager={manager}"); + sync.Write(-1); + } + else + { + sync.Write(index); + sync.Write(def); + sync.Write(manager); + } + } + else + { + var index = sync.Read(); + // If negative - it's null + if (index < 0) + return; + + var def = sync.Read(); + var manager = sync.Read(); + var list = pipeNetManagerPipeNetsListField(manager); + var currentIndex = 0; + + foreach (var currentPipeNet in list) + { + if (def == pipeNetDefField(currentPipeNet)) + { + if (currentIndex == index) + { + pipeNet = currentPipeNet; + break; + } + + currentIndex++; + } + } + } + } + #endregion #region Faction Discovery diff --git a/Source/Mods/VanillaTemperatureExpanded.cs b/Source/Mods/VanillaTemperatureExpanded.cs new file mode 100644 index 0000000..ec88304 --- /dev/null +++ b/Source/Mods/VanillaTemperatureExpanded.cs @@ -0,0 +1,29 @@ +using HarmonyLib; +using Multiplayer.API; +using Verse; + +namespace Multiplayer.Compat; + +/// Vanilla Temperature Expanded by Oskar Potocki, xrushha, Arquebus, Taranchuk +/// +/// +[MpCompatFor("VanillaExpanded.Temperature")] +public class VanillaTemperatureExpanded +{ + public VanillaTemperatureExpanded(ModContentPack mod) + { + LongEventHandler.ExecuteWhenFinished(LatePatch); + + // Unlink/relink + MpCompat.RegisterLambdaDelegate("VanillaTemperatureExpanded.Comps.CompAcTempControl", nameof(ThingComp.CompGetGizmosExtra), 0); + } + + private static void LatePatch() + { + var type = AccessTools.TypeByName("VanillaTemperatureExpanded.Buildings.Building_AcControlUnit"); + // Change temperature by +/- 1/10 + MP.RegisterSyncMethod(type, "InterfaceChangeTargetNetworkTemperature"); + // Reset temperature + MP.RegisterSyncMethodLambda(type, nameof(Thing.GetGizmos), 2); + } +} \ No newline at end of file