Beispiel #1
0
        private static void WriteData(ByteWriter data, DesignatorMode mode, Designator designator)
        {
            Sync.WriteSync(data, mode);
            Sync.WriteSync(data, designator);

            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);
            }
        }
Beispiel #2
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.log.Node("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.ToArray());
            Multiplayer.WriterLog.nodes.Add(writer.log.current);

            return(false);
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
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.log.Node("Designate single cell: " + designator.GetType());

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

            Multiplayer.Client.SendCommand(CommandType.Designator, map.uniqueID, writer.ToArray());
            Multiplayer.WriterLog.nodes.Add(writer.log.current);

            return(false);
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
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.ToArray());
        }
Beispiel #7
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.log.Node("Designate thing: " + __0 + " " + designator.GetType());

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

            Multiplayer.Client.SendCommand(CommandType.Designator, map.uniqueID, writer.ToArray());
            Multiplayer.WriterLog.nodes.Add(writer.log.current);

            MoteMaker.ThrowMetaPuffs(__0);

            return(false);
        }
Beispiel #8
0
        public static XmlDocument SaveAndReload()
        {
            Multiplayer.reloading = true;

            var worldGridSaved     = Find.WorldGrid;
            var worldRendererSaved = Find.World.renderer;
            var tweenedPos         = new Dictionary <int, Vector3>();
            var drawers            = new Dictionary <int, MapDrawer>();
            var localFactionId     = Multiplayer.RealPlayerFaction.loadID;
            var mapCmds            = new Dictionary <int, Queue <ScheduledCommand> >();
            var planetRenderMode   = Find.World.renderer.wantedMode;
            var chatWindow         = ChatWindow.Opened;

            var selectedData = new ByteWriter();

            Sync.WriteSync(selectedData, Find.Selector.selected.OfType <ISelectable>().ToList());

            //RealPlayerFaction = DummyFaction;

            foreach (Map map in Find.Maps)
            {
                drawers[map.uniqueID] = map.mapDrawer;
                //RebuildRegionsAndRoomsPatch.copyFrom[map.uniqueID] = map.regionGrid;

                foreach (Pawn p in map.mapPawns.AllPawnsSpawned)
                {
                    tweenedPos[p.thingIDNumber] = p.drawer.tweener.tweenedPos;
                }

                mapCmds[map.uniqueID] = map.AsyncTime().cmds;
            }

            mapCmds[ScheduledCommand.Global] = Multiplayer.WorldComp.cmds;

            Stopwatch   watch   = Stopwatch.StartNew();
            XmlDocument gameDoc = SaveGame();

            Log.Message("Saving took " + watch.ElapsedMilliseconds);

            MapDrawerRegenPatch.copyFrom     = drawers;
            WorldGridCachePatch.copyFrom     = worldGridSaved;
            WorldRendererCachePatch.copyFrom = worldRendererSaved;

            LoadInMainThread(gameDoc);

            Multiplayer.RealPlayerFaction = Find.FactionManager.GetById(localFactionId);

            foreach (Map m in Find.Maps)
            {
                foreach (Pawn p in m.mapPawns.AllPawnsSpawned)
                {
                    if (tweenedPos.TryGetValue(p.thingIDNumber, out Vector3 v))
                    {
                        p.drawer.tweener.tweenedPos    = v;
                        p.drawer.tweener.lastDrawFrame = Time.frameCount;
                    }
                }

                m.AsyncTime().cmds = mapCmds[m.uniqueID];
            }

            if (chatWindow != null)
            {
                Find.WindowStack.Add_KeepRect(chatWindow);
            }

            var selectedReader = new ByteReader(selectedData.ToArray())
            {
                context = new MpContext()
                {
                    map = Find.CurrentMap
                }
            };

            Find.Selector.selected = Sync.ReadSync <List <ISelectable> >(selectedReader).NotNull().Cast <object>().ToList();

            Find.World.renderer.wantedMode = planetRenderMode;
            Multiplayer.WorldComp.cmds     = mapCmds[ScheduledCommand.Global];

            Multiplayer.reloading = false;

            return(gameDoc);
        }
        public static XmlDocument SaveAndReload()
        {
            Multiplayer.reloading = true;

            var worldGridSaved     = Find.WorldGrid;
            var worldRendererSaved = Find.World.renderer;
            var tweenedPos         = new Dictionary <int, Vector3>();
            var drawers            = new Dictionary <int, MapDrawer>();
            var localFactionId     = Multiplayer.RealPlayerFaction.loadID;
            var mapCmds            = new Dictionary <int, Queue <ScheduledCommand> >();
            var planetRenderMode   = Find.World.renderer.wantedMode;
            var chatWindow         = ChatWindow.Opened;
            var oldSong            = Find.MusicManagerPlay.lastStartedSong;
            var oldSongTime        = Find.MusicManagerPlay.audioSource?.time;

            var selectedData = new ByteWriter();

            Sync.WriteSync(selectedData, Find.Selector.selected.OfType <ISelectable>().ToList());

            //RealPlayerFaction = DummyFaction;

            foreach (Map map in Find.Maps)
            {
                drawers[map.uniqueID] = map.mapDrawer;
                //RebuildRegionsAndRoomsPatch.copyFrom[map.uniqueID] = map.regionGrid;

                foreach (Pawn p in map.mapPawns.AllPawnsSpawned)
                {
                    tweenedPos[p.thingIDNumber] = p.drawer.tweener.tweenedPos;
                }

                mapCmds[map.uniqueID] = map.AsyncTime().cmds;
            }

            mapCmds[ScheduledCommand.Global] = Multiplayer.WorldComp.cmds;

            Stopwatch   watch   = Stopwatch.StartNew();
            XmlDocument gameDoc = SaveGame();

            Log.Message("Saving took " + watch.ElapsedMilliseconds);

            MapDrawerRegenPatch.copyFrom     = drawers;
            WorldGridCachePatch.copyFrom     = worldGridSaved;
            WorldRendererCachePatch.copyFrom = worldRendererSaved;

            LoadInMainThread(gameDoc);

            Multiplayer.RealPlayerFaction = Find.FactionManager.GetById(localFactionId);

            foreach (Map m in Find.Maps)
            {
                foreach (Pawn p in m.mapPawns.AllPawnsSpawned)
                {
                    if (tweenedPos.TryGetValue(p.thingIDNumber, out Vector3 v))
                    {
                        p.drawer.tweener.tweenedPos    = v;
                        p.drawer.tweener.lastDrawFrame = Time.frameCount;
                    }
                }

                m.AsyncTime().cmds = mapCmds[m.uniqueID];
            }

            if (chatWindow != null)
            {
                Find.WindowStack.Add_KeepRect(chatWindow);
            }

            if (oldSong != null && oldSongTime != null)
            {
                // resume previous music track
                Find.MusicManagerPlay.MusicUpdate();         // seems to need to run for a tick after a reload to avoid null exceptions
                Find.MusicManagerPlay.ForceStartSong(oldSong, false);
                Find.MusicManagerPlay.songWasForced = false; // make it look like this song was chosen naturally, so the leadin to the next song is smooth
                Find.MusicManagerPlay.recentSongs.Dequeue();
                Find.MusicManagerPlay.audioSource.time = (float)oldSongTime;
            }

            var selectedReader = new ByteReader(selectedData.ToArray())
            {
                context = new MpContext()
                {
                    map = Find.CurrentMap
                }
            };

            Find.Selector.selected = Sync.ReadSync <List <ISelectable> >(selectedReader).NotNull().Cast <object>().ToList();

            Find.World.renderer.wantedMode = planetRenderMode;
            Multiplayer.WorldComp.cmds     = mapCmds[ScheduledCommand.Global];

            Multiplayer.reloading = false;

            return(gameDoc);
        }