Exemplo n.º 1
0
 public override void Start()
 {
     base.Start();
     this.musicManagerPlay = new MusicManagerPlay();
     if (Find.GameInitData != null && !Find.GameInitData.gameToLoad.NullOrEmpty())
     {
         LongEventHandler.QueueLongEvent(delegate
         {
             SavedGameLoader.LoadGameFromSaveFile(Find.GameInitData.gameToLoad);
         }, "LoadingLongEvent", true, GameAndMapInitExceptionHandlers.ErrorWhileLoadingGame);
     }
     else
     {
         LongEventHandler.QueueLongEvent(delegate
         {
             if (Current.Game == null)
             {
                 Root_Play.SetupForQuickTestPlay();
             }
             Current.Game.InitNewGame();
         }, "GeneratingMap", true, GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap);
     }
     LongEventHandler.QueueLongEvent(delegate
     {
         ScreenFader.SetColor(Color.black);
         ScreenFader.StartFade(Color.clear, 0.5f);
     }, null, false, null);
 }
Exemplo n.º 2
0
        public static void AppropriateSongNowData()
        {
            MethodInfo       AppropriateNowInfo = AccessTools.Method(typeof(MusicManagerPlay), "AppropriateNow");
            MusicManagerPlay mmp           = Find.MusicManagerPlay;
            StringBuilder    stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Songs appropriate to play now:");
            foreach (SongDef item in DefDatabase <SongDef> .AllDefs.Where((SongDef s) => (bool)AppropriateNowInfo.Invoke(mmp, new object[] { s })))
            {
                stringBuilder.AppendLine("   " + item.defName);
            }
            stringBuilder.AppendLine();
            Log.Message(stringBuilder.ToString());
        }
Exemplo n.º 3
0
 public override void Start()
 {
     Log.ResetMessageCount();
     base.Start();
     try
     {
         musicManagerPlay = new MusicManagerPlay();
         FileInfo autostart = Root.checkedAutostartSaveFile ? null : SaveGameFilesUtility.GetAutostartSaveFile();
         Root.checkedAutostartSaveFile = true;
         if (autostart != null)
         {
             LongEventHandler.QueueLongEvent(delegate
             {
                 SavedGameLoaderNow.LoadGameFromSaveFileNow(Path.GetFileNameWithoutExtension(autostart.Name));
             }, "LoadingLongEvent", doAsynchronously: true, GameAndMapInitExceptionHandlers.ErrorWhileLoadingGame);
         }
         else if (Find.GameInitData != null && !Find.GameInitData.gameToLoad.NullOrEmpty())
         {
             LongEventHandler.QueueLongEvent(delegate
             {
                 SavedGameLoaderNow.LoadGameFromSaveFileNow(Find.GameInitData.gameToLoad);
             }, "LoadingLongEvent", doAsynchronously: true, GameAndMapInitExceptionHandlers.ErrorWhileLoadingGame);
         }
         else
         {
             LongEventHandler.QueueLongEvent(delegate
             {
                 if (Current.Game == null)
                 {
                     SetupForQuickTestPlay();
                 }
                 Current.Game.InitNewGame();
             }, "GeneratingMap", doAsynchronously: true, GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap);
         }
         LongEventHandler.QueueLongEvent(delegate
         {
             ScreenFader.SetColor(Color.black);
             ScreenFader.StartFade(Color.clear, 0.5f);
         }, null, doAsynchronously: false, null);
     }
     catch (Exception arg)
     {
         Log.Error("Critical error in root Start(): " + arg);
     }
 }
Exemplo n.º 4
0
        public static TempGameData SaveAndReload()
        {
            //SimpleProfiler.Start();
            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();

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

            //Multiplayer.RealPlayerFaction = Multiplayer.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;

            DeepProfiler.Start("Multiplayer SaveAndReload: Save");
            //WriteElementPatch.cachedVals = new Dictionary<string, object>();
            //WriteElementPatch.id = 0;
            var gameData = SaveGameData();

            DeepProfiler.End();
            //Log.Message($"Saving took {WriteElementPatch.cachedVals.Count} {WriteElementPatch.cachedVals.FirstOrDefault()}");

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

            MusicManagerPlay musicManager = null;

            if (Find.MusicManagerPlay.gameObjectCreated)
            {
                var musicTransform = Find.MusicManagerPlay.audioSource.transform;
                if (musicTransform.parent == Find.Root.soundRoot.sourcePool.sourcePoolCamera.cameraSourcesContainer.transform)
                {
                    musicTransform.parent = musicTransform.parent.parent;
                }

                musicManager = Find.MusicManagerPlay;
            }

            //SpawnSetupPatch.total = 0;
            //SpawnSetupPatch.total2 = new long[SpawnSetupPatch.total2.Length];

            LoadInMainThread(gameData);

            if (musicManager != null)
            {
                Current.Root_Play.musicManagerPlay = musicManager;
            }

            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 = SyncSerialization.ReadSync <List <ISelectable> >(selectedReader).AllNotNull().Cast <object>().ToList();

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

            Multiplayer.reloading = false;
            //SimpleProfiler.Pause();

            //Log.Message($"allocs {(double)SpawnSetupPatch.total2.Sum() / Stopwatch.Frequency * 1000} ({SpawnSetupPatch.total2.Select((l,i) => $"{SpawnSetupPatch.methods[i]}: {(double)l / Stopwatch.Frequency * 1000}").Join(delimiter: "\n")}) {SpawnSetupPatch.total} {AllocsPrefixClass.allocs} {CustomXmlElement.n} {CustomXmlElement.m} {CustomXmlElement.n - CustomXmlElement.m} {(double)CustomXmlElement.n/CustomXmlElement.m}");

            return(gameData);
        }
Exemplo n.º 5
0
 public override void Start()
 {
     Log.ResetMessageCount();
     base.Start();
     try
     {
         this.musicManagerPlay = new MusicManagerPlay();
         FileInfo autostart = (!Root.checkedAutostartSaveFile) ? SaveGameFilesUtility.GetAutostartSaveFile() : null;
         Root.checkedAutostartSaveFile = true;
         if (autostart != null)
         {
             Action action = delegate()
             {
                 SavedGameLoaderNow.LoadGameFromSaveFileNow(Path.GetFileNameWithoutExtension(autostart.Name));
             };
             string textKey          = "LoadingLongEvent";
             bool   doAsynchronously = true;
             if (Root_Play.< > f__mg$cache0 == null)
             {
                 Root_Play.< > f__mg$cache0 = new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileLoadingGame);
             }
             LongEventHandler.QueueLongEvent(action, textKey, doAsynchronously, Root_Play.< > f__mg$cache0);
         }
         else if (Find.GameInitData != null && !Find.GameInitData.gameToLoad.NullOrEmpty())
         {
             Action action2 = delegate()
             {
                 SavedGameLoaderNow.LoadGameFromSaveFileNow(Find.GameInitData.gameToLoad);
             };
             string textKey2          = "LoadingLongEvent";
             bool   doAsynchronously2 = true;
             if (Root_Play.< > f__mg$cache1 == null)
             {
                 Root_Play.< > f__mg$cache1 = new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileLoadingGame);
             }
             LongEventHandler.QueueLongEvent(action2, textKey2, doAsynchronously2, Root_Play.< > f__mg$cache1);
         }
         else
         {
             Action action3 = delegate()
             {
                 if (Current.Game == null)
                 {
                     Root_Play.SetupForQuickTestPlay();
                 }
                 Current.Game.InitNewGame();
             };
             string textKey3          = "GeneratingMap";
             bool   doAsynchronously3 = true;
             if (Root_Play.< > f__mg$cache2 == null)
             {
                 Root_Play.< > f__mg$cache2 = new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap);
             }
             LongEventHandler.QueueLongEvent(action3, textKey3, doAsynchronously3, Root_Play.< > f__mg$cache2);
         }
         LongEventHandler.QueueLongEvent(delegate()
         {
             ScreenFader.SetColor(Color.black);
             ScreenFader.StartFade(Color.clear, 0.5f);
         }, null, false, null);
     }
     catch (Exception arg)
     {
         Log.Error("Critical error in root Start(): " + arg, false);
     }
 }