예제 #1
0
        public static bool DesignateMultiCell(Designator __instance, IEnumerable <IntVec3> __0)
        {
            if (!Multiplayer.ShouldSync)
            {
                return(true);
            }

            // No cells implies Finalize(false), which currently doesn't cause side effects
            if (__0.Count() == 0)
            {
                return(true);
            }

            Designator designator = __instance;

            Map map = Find.CurrentMap;
            LoggingByteWriter writer = new LoggingByteWriter();

            writer.LogNode("Designate multi cell: " + designator.GetType());
            IntVec3[] cellArray = __0.ToArray();

            WriteData(writer, DesignatorMode.MultiCell, designator);
            Sync.WriteSync(writer, cellArray);

            Multiplayer.Client.SendCommand(CommandType.Designator, map.uniqueID, writer.GetArray());
            Multiplayer.PacketLog.nodes.Add(writer.current);

            return(false);
        }
예제 #2
0
        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.GetArray());

            return(true);
        }
예제 #3
0
        public static bool DesignateSingleCell(Designator __instance, IntVec3 __0)
        {
            if (!Multiplayer.ShouldSync)
            {
                return(true);
            }

            Designator designator = __instance;

            Map map = Find.CurrentMap;
            LoggingByteWriter writer = new LoggingByteWriter();

            writer.LogNode("Designate single cell: " + designator.GetType());

            WriteData(writer, DesignatorMode.SingleCell, designator);
            Sync.WriteSync(writer, __0);

            Multiplayer.Client.SendCommand(CommandType.Designator, map.uniqueID, writer.GetArray());
            Multiplayer.PacketLog.nodes.Add(writer.current);

            return(false);
        }
예제 #4
0
        /// <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.GetArray());

            return(true);
        }
예제 #5
0
        private void ActualSync(A target, B arg0, C arg1, Action original)
        {
            LoggingByteWriter writer  = new LoggingByteWriter();
            MpContext         context = writer.MpContext();

            writer.LogNode("Sync action");

            writer.WriteInt32(SyncId);

            Sync.WriteSync(writer, target);
            Sync.WriteSync(writer, arg0);
            Sync.WriteSync(writer, arg1);

            writer.WriteInt32(GenText.StableStringHash(original.Method.MethodDesc()));
            Log.Message(original.Method.MethodDesc());

            int mapId = writer.MpContext().map?.uniqueID ?? -1;

            writer.LogNode("Map id: " + mapId);
            Multiplayer.PacketLog.nodes.Add(writer.current);

            Multiplayer.Client.SendCommand(CommandType.Sync, mapId, writer.GetArray());
        }
예제 #6
0
        public static bool DesignateThing(Designator __instance, Thing __0)
        {
            if (!Multiplayer.ShouldSync)
            {
                return(true);
            }

            Designator designator = __instance;

            Map map = Find.CurrentMap;
            LoggingByteWriter writer = new LoggingByteWriter();

            writer.LogNode("Designate thing: " + __0 + " " + designator.GetType());

            WriteData(writer, DesignatorMode.Thing, designator);
            Sync.WriteSync(writer, __0);

            Multiplayer.Client.SendCommand(CommandType.Designator, map.uniqueID, writer.GetArray());
            Multiplayer.PacketLog.nodes.Add(writer.current);

            MoteMaker.ThrowMetaPuffs(__0);

            return(false);
        }
예제 #7
0
        /// <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.GetArray());

            lastSendTime = Utils.MillisNow;

            return(true);
        }