private static void WriteData(ByteWriter data, DesignatorMode mode, Designator designator) { Type designatorType = designator.GetType(); Sync.WriteSync(data, mode); Sync.WriteSync(data, (ushort)Array.IndexOf(Sync.designatorTypes, designatorType)); Sync.WriteSyncObject(data, designator, designatorType); if (designator is Designator_AreaAllowed) { Sync.WriteSync(data, Designator_AreaAllowed.SelectedArea); } if (designator is Designator_Place place) { Sync.WriteSync(data, place.placingRot); } if (designator is Designator_Build build && build.PlacingDef.MadeFromStuff) { Sync.WriteSync(data, build.stuffDef); } if (designator is Designator_Install) { Sync.WriteSync(data, ThingToInstall()); } if (designator is Designator_Zone) { Sync.WriteSync(data, Find.Selector.SelectedZone); } }
public bool DoSync(object delegateInstance, object[] args) { if (!Multiplayer.ShouldSync) { return(false); } LoggingByteWriter writer = new LoggingByteWriter(); MpContext context = writer.MpContext(); writer.LogNode($"Sync delegate: {delegateType} method: {method}"); writer.LogNode("Patch: " + patch?.FullDescription()); writer.WriteInt32(syncId); Sync.WriteContext(this, writer); int mapId = ScheduledCommand.Global; IEnumerable <object> fields = fieldPaths.Select(p => delegateInstance.GetPropertyOrField(p)); EnumerableHelper.ProcessCombined(fields.Concat(args), fieldTypes.Concat(argTypes), (obj, type) => { if (type.IsCompilerGenerated()) { return; } Sync.WriteSyncObject(writer, obj, type); if (context.map is Map map) { if (mapId != ScheduledCommand.Global && mapId != map.uniqueID) { throw new Exception("SyncDelegate map mismatch"); } mapId = map.uniqueID; } }); writer.LogNode("Map id: " + mapId); Multiplayer.PacketLog.nodes.Add(writer.current); Multiplayer.Client.SendCommand(CommandType.Sync, mapId, writer.ToArray()); return(true); }
/// <summary> /// Returns whether the original should cancelled /// </summary> public bool DoSync(object target, object value, object index = null) { if (!(inGameLoop || Multiplayer.ShouldSync)) { return(false); } LoggingByteWriter writer = new LoggingByteWriter(); MpContext context = writer.MpContext(); writer.LogNode("Sync field " + memberPath); writer.WriteInt32(syncId); int mapId = ScheduledCommand.Global; if (targetType != null) { Sync.WriteSyncObject(writer, target, targetType); if (context.map != null) { mapId = context.map.uniqueID; } } Sync.WriteSyncObject(writer, value, fieldType); if (indexType != null) { Sync.WriteSyncObject(writer, index, indexType); } writer.LogNode("Map id: " + mapId); Multiplayer.PacketLog.nodes.Add(writer.current); Multiplayer.Client.SendCommand(CommandType.Sync, mapId, writer.ToArray()); return(true); }
private static void WriteData(ByteWriter data, DesignatorMode mode, Designator designator) { Sync.WriteSync(data, mode); Sync.WriteSyncObject(data, designator, designator.GetType()); // These affect the Global context and shouldn't be SyncWorkers // Read at MapAsyncTimeComp.SetDesignatorState if (designator is Designator_AreaAllowed) { Sync.WriteSync(data, Designator_AreaAllowed.SelectedArea); } if (designator is Designator_Install install) { Sync.WriteSync(data, install.MiniToInstallOrBuildingToReinstall); } if (designator is Designator_Zone) { Sync.WriteSync(data, Find.Selector.SelectedZone); } }
/// <summary> /// Returns whether the original should be cancelled /// </summary> public bool DoSync(object target, params object[] args) { if (!Multiplayer.ShouldSync) { return(false); } // todo limit per specific target/argument //if (Utils.MillisNow - lastSendTime < minTime) // return true; LoggingByteWriter writer = new LoggingByteWriter(); MpContext context = writer.MpContext(); writer.LogNode("Sync method " + method.FullDescription()); writer.WriteInt32(syncId); Sync.WriteContext(this, writer); Map map = writer.MpContext().map; if (targetType != null) { Sync.WriteSyncObject(writer, target, targetType); if (context.map is Map newMap) { map = newMap; } } for (int i = 0; i < argTypes.Length; i++) { var argType = argTypes[i]; Sync.WriteSyncObject(writer, args[i], argType); if (argType.contextMap && args[i] is Map contextMap) { map = contextMap; } if (context.map is Map newMap) { if (map != null && map != newMap) { throw new Exception($"SyncMethod map mismatch ({map?.uniqueID} and {newMap?.uniqueID})"); } map = newMap; } } int mapId = map?.uniqueID ?? ScheduledCommand.Global; writer.LogNode("Map id: " + mapId); Multiplayer.PacketLog.nodes.Add(writer.current); Multiplayer.Client.SendCommand(CommandType.Sync, mapId, writer.ToArray()); lastSendTime = Utils.MillisNow; return(true); }