Exemplo n.º 1
0
        /// <summary>
        /// Starts saving the game in the background. This function is not reentrant!
        /// </summary>
        /// <param name="filename">The file name where the save should be stored.</param>
        public void StartSave(string filename)
        {
            var  buffer = new MemoryStream(BUFFER_SIZE);
            var  inst   = SaveLoader.Instance;
            bool save   = true;

            if (inst != null)
            {
                var trLoader = Traverse.Create(inst);
                KSerialization.Manager.Clear();
#if DEBUG
                PUtil.LogDebug("Starting serialization of save");
#endif
                bool compress = true;
                // This field is currently always true
                try {
                    compress = trLoader.GetField <bool>("compressSaveData");
                } catch { }
                // Keep this part on the foreground
                try {
                    trLoader.CallMethod("Save", new BinaryWriter(buffer));
                } catch (Exception e) {
                    buffer.Dispose();
                    PUtil.LogError("Error when saving game:");
                    PUtil.LogException(e);
                    save = false;
                }
                // In Unity 4 GetComponent no longer works on background threads
                RetireColonyUtility.SaveColonySummaryData();
                if (save)
                {
                    StartSave(new BackgroundSaveData(buffer, compress, filename));
                }
            }
        }
Exemplo n.º 2
0
 private bool LoadSlideshow(RetiredColonyData data)
 {
     clearCurrentSlideshow();
     currentSlideshowFiles = RetireColonyUtility.LoadColonySlideshowFiles(data.colonyName);
     slideshow.SetFiles(currentSlideshowFiles, -1);
     return(currentSlideshowFiles != null && currentSlideshowFiles.Length > 0);
 }
Exemplo n.º 3
0
            /// <summary>
            /// Applied before RenderEveryTick runs.
            /// </summary>
            internal static bool Prefix(ColonyAchievementTracker __instance)
            {
                var mode = FastTrackOptions.Instance.DisableAchievements;

                if (mode != FastTrackOptions.AchievementDisable.Always && (mode ==
                                                                           FastTrackOptions.AchievementDisable.Never || TrackAchievements()))
                {
                    var allAchievements = Db.Get().ColonyAchievements.resources;
                    var achievements    = __instance.achievements;
                    // Update one per frame
                    int index = __instance.updatingAchievement;
                    if (index >= achievements.Count || index >= allAchievements.Count)
                    {
                        index = 0;
                    }
                    string key = allAchievements[index].Id;
                    __instance.updatingAchievement = index + 1;
                    // If achievement has not already failed or succeeded
                    if (achievements.TryGetValue(key, out ColonyAchievementStatus status) &&
                        !status.success && !status.failed)
                    {
                        status.UpdateAchievement();
                        if (status.success && !status.failed)
                        {
                            ColonyAchievementTracker.UnlockPlatformAchievement(key);
                            __instance.completedAchievementsToDisplay.Add(key);
                            __instance.TriggerNewAchievementCompleted(key);
                            RetireColonyUtility.SaveColonySummaryData();
                        }
                    }
                }
                return(false);
            }
Exemplo n.º 4
0
 /// <summary>
 /// Cleans up old autosaves.
 /// </summary>
 /// <param name="filename">The file name that is being saved.</param>
 private void CleanAutosaves(string filename)
 {
     RetireColonyUtility.SaveColonySummaryData();
     if (!Klei.GenericGameSettings.instance.keepAllAutosaves)
     {
         var saveFiles = SaveLoader.GetSaveFiles(Path.GetDirectoryName(filename));
         // Clean up old autosaves and their preview images
         for (int i = saveFiles.Count - 1; i >= SaveLoader.MAX_AUTOSAVE_FILES - 1; i--)
         {
             string autoName = saveFiles[i], autoImage = Path.ChangeExtension(
                 autoName, ".png");
             try {
                 PUtil.LogDebug("Deleting old autosave: " + autoName);
                 File.Delete(autoName);
             } catch (Exception e) {
                 PUtil.LogWarning("Problem deleting old autosave: " + autoName);
                 PUtil.LogExcWarn(e);
             }
             try {
                 if (File.Exists(autoImage))
                 {
                     File.Delete(autoImage);
                 }
             } catch (Exception e) {
                 PUtil.LogWarning("Problem deleting old screenshot: " + autoImage);
                 PUtil.LogExcWarn(e);
             }
         }
     }
 }
Exemplo n.º 5
0
            /// <summary>
            /// Applied before DelayedSave runs.
            /// </summary>
            internal static System.Collections.IEnumerator Postfix(
                System.Collections.IEnumerator result, string filename, bool isAutoSave,
                Game.SavingPostCB ___activatePostCB, bool updateSavePointer,
                Game.SavingActiveCB ___activateActiveCB)
            {
                var inst = PlayerController.Instance;

                if (isAutoSave)
                {
                    // Wait for player to stop dragging
                    while (inst.IsDragging())
                    {
                        yield return(null);
                    }
                    inst.CancelDragging();
                    inst.AllowDragging(false);
                    BackgroundAutosave.DisableSaving();
                    try {
                        yield return(null);

                        if (___activateActiveCB != null)
                        {
                            ___activateActiveCB();
                            yield return(null);
                        }
                        // Save in the background
                        Game.Instance.timelapser?.SaveColonyPreview(filename);
                        BackgroundAutosave.Instance.StartSave(filename);
                        yield return(null);

                        RetireColonyUtility.SaveColonySummaryData();
                        // Wait asynchronously for it
                        while (!BackgroundAutosave.Instance.CheckSaveStatus())
                        {
                            yield return(null);
                        }
                        if (updateSavePointer)
                        {
                            SaveLoader.SetActiveSaveFilePath(filename);
                        }
                        ___activatePostCB?.Invoke();
                        for (int i = 0; i < 5; i++)
                        {
                            yield return(null);
                        }
                    } finally {
                        BackgroundAutosave.EnableSaving();
                        inst.AllowDragging(true);
                    }
                    yield break;
                }
                else
                {
                    // Original method
                    while (result.MoveNext())
                    {
                        yield return(result.Current);
                    }
                }
            }
Exemplo n.º 6
0
        // Adapted from WriteToPng method
        public static void CustomWriteToPng(RenderTexture renderTex)
        {
            Texture2D texture2D = new Texture2D(renderTex.width, renderTex.height, TextureFormat.ARGB32, false);

            texture2D.ReadPixels(new Rect(0f, 0f, renderTex.width, renderTex.height), 0, 0);
            texture2D.Apply();
            byte[] bytes = texture2D.EncodeToPNG();
            Object.Destroy(texture2D);
            if (!Directory.Exists(Util.RootFolder()))
            {
                Directory.CreateDirectory(Util.RootFolder());
            }
            string text = Path.Combine(Util.RootFolder(), "HD_Screenshots");

            if (!Directory.Exists(text))
            {
                Directory.CreateDirectory(text);
            }
            string name = RetireColonyUtility.StripInvalidCharacters(SaveGame.Instance.BaseName);

            DebugUtil.LogArgs(new object[]
            {
                "Saving screenshot to",
                text
            });
            savedPath = text;
            string format = "0000.##";

            text = text + Path.DirectorySeparatorChar + name + "_cycle_" + GameClock.Instance.GetCycle().ToString(format);

            File.WriteAllBytes(text + ".png", bytes);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Saves a preview image to disk in the background.
        /// </summary>
        /// <param name="data">The uncompressed preview image data.</param>
        private void DoSave(BackgroundTimelapseData data)
        {
            var    screenData  = data.TextureData;
            string previewPath = data.SaveGamePath;
            bool   preview     = data.Preview;

            byte[] rawPNG;
            // Encode PNG (this is the woofy part on high resolution)
#if DEBUG
            PUtil.LogDebug("Encoding preview image");
#endif
            try {
                rawPNG = screenData.EncodeToPNG();
            } finally {
                data.Dispose();
            }
            try {
                string retiredPath = Path.Combine(Util.RootFolder(), Util.
                                                  GetRetiredColoniesFolderName());
                if (!Directory.Exists(retiredPath))
                {
                    // This call is recursive
                    Directory.CreateDirectory(retiredPath);
                }
                string saveName = RetireColonyUtility.StripInvalidCharacters(SaveGame.Instance.
                                                                             BaseName), path;
                if (preview)
                {
                    // Colony preview
                    path = Path.ChangeExtension(previewPath, ".png");
                }
                else
                {
                    string saveFolder = Path.Combine(retiredPath, saveName);
                    if (!Directory.Exists(saveFolder))
                    {
                        Directory.CreateDirectory(saveFolder);
                    }
                    // Suffix file name with the current cycle
                    saveName += "_cycle" + GameClock.Instance.GetCycle().ToString("0000.##");
                    // debugScreenShot is always false
                    path = Path.Combine(saveFolder, saveName);
                }
                PUtil.LogDebug("Saving screenshot to " + path);
                File.WriteAllBytes(path, rawPNG);
                rawPNG = null;
#if DEBUG
                PUtil.LogDebug("Background screenshot save complete");
#endif
            } catch (IOException e) {
                PUtil.LogWarning("Unable to save colony timelapse screenshot:");
                PUtil.LogExcWarn(e);
            } catch (UnauthorizedAccessException e) {
                PUtil.LogWarning("Unable to save colony timelapse screenshot:");
                PUtil.LogExcWarn(e);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Saves a preview image to disk in the background.
        /// </summary>
        /// <param name="data">The uncompressed preview image data.</param>
        private void DoSave(BackgroundTimelapseData data)
        {
            var    screenData  = data.RawData;
            string previewPath = data.SaveGamePath;
            bool   preview     = data.Preview;

            try {
                string retiredPath = Path.Combine(Util.RootFolder(), Util.
                                                  GetRetiredColoniesFolderName());
                if (!Directory.Exists(retiredPath))
                {
                    // This call is recursive
                    Directory.CreateDirectory(retiredPath);
                }
                string saveName = RetireColonyUtility.StripInvalidCharacters(SaveGame.Instance.
                                                                             BaseName), path;
                if (preview)
                {
                    // Colony preview
                    path = Path.ChangeExtension(previewPath, ".png");
                }
                else
                {
                    string saveFolder = Path.Combine(retiredPath, saveName), worldName =
                        data.WorldName;
                    if (!string.IsNullOrWhiteSpace(worldName))
                    {
                        saveFolder = Path.Combine(saveFolder, data.WorldID.ToString("D5"));
                        saveFolder = Path.Combine(saveFolder, worldName);
                        saveName   = worldName;
                    }
                    if (!Directory.Exists(saveFolder))
                    {
                        Directory.CreateDirectory(saveFolder);
                    }
                    // Suffix file name with the current cycle
                    saveName += "_cycle_" + GameClock.Instance.GetCycle().ToString("0000.##") +
                                ".png";
                    // debugScreenShot is always false
                    path = Path.Combine(saveFolder, saveName);
                }
                PUtil.LogDebug("Saving screenshot to " + path);
                File.WriteAllBytes(path, data.RawData);
#if DEBUG
                PUtil.LogDebug("Background screenshot save complete");
#endif
            } catch (IOException e) {
                PUtil.LogWarning("Unable to save colony timelapse screenshot:");
                PUtil.LogExcWarn(e);
            } catch (UnauthorizedAccessException e) {
                PUtil.LogWarning("Unable to save colony timelapse screenshot:");
                PUtil.LogExcWarn(e);
            }
        }
Exemplo n.º 9
0
    private bool LoadScreenshot(RetiredColonyData data)
    {
        clearCurrentSlideshow();
        Sprite sprite = RetireColonyUtility.LoadRetiredColonyPreview(data.colonyName);

        if ((UnityEngine.Object)sprite != (UnityEngine.Object)null)
        {
            slideshow.setSlide(sprite);
            CorrectTimelapseImageSize(sprite);
        }
        return((UnityEngine.Object)sprite != (UnityEngine.Object)null);
    }
Exemplo n.º 10
0
 public RetiredColonyData GetColonyDataByBaseName(string name)
 {
     name = RetireColonyUtility.StripInvalidCharacters(name);
     for (int i = 0; i < retiredColonyData.Length; i++)
     {
         if (RetireColonyUtility.StripInvalidCharacters(retiredColonyData[i].colonyName) == name)
         {
             return(retiredColonyData[i]);
         }
     }
     return(null);
 }
 public static void ActivateRetiredColoniesScreen(GameObject parent, string colonyID = "", string[] newlyAchieved = null)
 {
     if ((UnityEngine.Object)RetiredColonyInfoScreen.Instance == (UnityEngine.Object)null)
     {
         Util.KInstantiateUI(ScreenPrefabs.Instance.RetiredColonyInfoScreen.gameObject, parent, true);
     }
     RetiredColonyInfoScreen.Instance.Show(true);
     if (!string.IsNullOrEmpty(colonyID))
     {
         if ((UnityEngine.Object)SaveGame.Instance != (UnityEngine.Object)null)
         {
             RetireColonyUtility.SaveColonySummaryData();
         }
         RetiredColonyInfoScreen.Instance.LoadColony(RetiredColonyInfoScreen.Instance.GetColonyDataByBaseName(colonyID));
     }
 }
Exemplo n.º 12
0
 private void LoadExplorer()
 {
     if (!((UnityEngine.Object)SaveGame.Instance != (UnityEngine.Object)null))
     {
         ToggleExplorer(true);
         this.retiredColonyData = RetireColonyUtility.LoadRetiredColonies(false);
         RetiredColonyData[] array = this.retiredColonyData;
         foreach (RetiredColonyData retiredColonyData in array)
         {
             RetiredColonyData   data       = retiredColonyData;
             GameObject          gameObject = Util.KInstantiateUI(colonyButtonPrefab, explorerGrid, true);
             HierarchyReferences component  = gameObject.GetComponent <HierarchyReferences>();
             string        text             = RetireColonyUtility.StripInvalidCharacters(data.colonyName);
             Sprite        sprite           = RetireColonyUtility.LoadRetiredColonyPreview(text);
             Image         reference        = component.GetReference <Image>("ColonyImage");
             RectTransform reference2       = component.GetReference <RectTransform>("PreviewUnavailableText");
             if ((UnityEngine.Object)sprite != (UnityEngine.Object)null)
             {
                 reference.enabled = true;
                 reference.sprite  = sprite;
                 reference2.gameObject.SetActive(false);
             }
             else
             {
                 reference.enabled = false;
                 reference2.gameObject.SetActive(true);
             }
             component.GetReference <LocText>("ColonyNameLabel").SetText(retiredColonyData.colonyName);
             component.GetReference <LocText>("CycleCountLabel").SetText(string.Format(UI.RETIRED_COLONY_INFO_SCREEN.CYCLE_COUNT, retiredColonyData.cycleCount.ToString()));
             component.GetReference <LocText>("DateLabel").SetText(retiredColonyData.date);
             gameObject.GetComponent <KButton>().onClick += delegate
             {
                 LoadColony(data);
             };
             string key = retiredColonyData.colonyName;
             int    num = 0;
             while (explorerColonyWidgets.ContainsKey(key))
             {
                 num++;
                 key = retiredColonyData.colonyName + "_" + num;
             }
             explorerColonyWidgets.Add(key, gameObject);
         }
     }
 }
 protected override void OnPrefabInit()
 {
     base.OnPrefabInit();
     Instance            = this;
     prevButton.onClick += delegate
     {
         ShowReport(currentReport.day - 1);
     };
     nextButton.onClick += delegate
     {
         ShowReport(currentReport.day + 1);
     };
     summaryButton.onClick += delegate
     {
         RetiredColonyData currentColonyRetiredColonyData = RetireColonyUtility.GetCurrentColonyRetiredColonyData();
         MainMenu.ActivateRetiredColoniesScreenFromData(PauseScreen.Instance.transform.parent.gameObject, currentColonyRetiredColonyData);
     };
     ConsumeMouseScroll = true;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Checks the colony summary to guess the date of the last possible death.
        /// </summary>
        private void InitGrimReaper()
        {
            // Look for the last dip in Duplicant count
            float lastValue = -1.0f;

            RetiredColonyData.RetiredColonyStatistic[] stats;
            try {
                var data = RetireColonyUtility.GetCurrentColonyRetiredColonyData();
                if ((stats = data?.Stats) != null && data.cycleCount > 0)
                {
                    var liveDupes = new SortedList <int, float>(stats.Length);
                    // Copy and sort the values
                    foreach (var cycleData in stats)
                    {
                        if (cycleData.id == RetiredColonyData.DataIDs.LiveDuplicants)
                        {
                            foreach (var entry in cycleData.value)
                            {
                                liveDupes[Mathf.RoundToInt(entry.first)] = entry.second;
                            }
                            break;
                        }
                    }
                    LastDeath = 0;
                    // Sorted by cycle now
                    foreach (var pair in liveDupes)
                    {
                        float dupes = pair.Value;
                        if (dupes < lastValue)
                        {
                            LastDeath = pair.Key;
                        }
                        lastValue = dupes;
                    }
                    liveDupes.Clear();
                }
            } catch (Exception e) {
                PUtil.LogWarning("Unable to determine the last date of death:");
                PUtil.LogExcWarn(e);
                LastDeath = GameClock.Instance?.GetCycle() ?? 0;
            }
        }
Exemplo n.º 15
0
 public override void Update()
 {
     if (lastDeath < 0)
     {
         // Look for the last dip in Duplicant count
         float lastValue = -1.0f;
         RetiredColonyData.RetiredColonyStatistic[] stats;
         var data = RetireColonyUtility.GetCurrentColonyRetiredColonyData();
         if ((stats = data?.Stats) != null && data.cycleCount > 0)
         {
             var liveDupes = new SortedList <int, float>(stats.Length);
             // Copy and sort the values
             foreach (var cycleData in stats)
             {
                 if (cycleData.id == RetiredColonyData.DataIDs.LiveDuplicants)
                 {
                     foreach (var entry in cycleData.value)
                     {
                         liveDupes[Mathf.RoundToInt(entry.first)] = entry.second;
                     }
                     break;
                 }
             }
             lastDeath = 0;
             // Sorted by cycle now
             foreach (var pair in liveDupes)
             {
                 float dupes = pair.Value;
                 if (dupes < lastValue)
                 {
                     lastDeath = pair.Key;
                 }
                 lastValue = dupes;
             }
             liveDupes.Clear();
         }
     }
 }
Exemplo n.º 16
0
 protected override void OnShow(bool show)
 {
     base.OnShow(show);
     if (show)
     {
         RefreshUIScale(null);
     }
     if ((UnityEngine.Object)Game.Instance != (UnityEngine.Object)null)
     {
         if (!show)
         {
             if (MusicManager.instance.SongIsPlaying("Music_Victory_03_StoryAndSummary"))
             {
                 MusicManager.instance.StopSong("Music_Victory_03_StoryAndSummary", true, STOP_MODE.ALLOWFADEOUT);
             }
         }
         else
         {
             retiredColonyData = RetireColonyUtility.LoadRetiredColonies(true);
             if (MusicManager.instance.SongIsPlaying("Music_Victory_03_StoryAndSummary"))
             {
                 MusicManager.instance.SetSongParameter("Music_Victory_03_StoryAndSummary", "songSection", 2f, true);
             }
         }
     }
     else if ((UnityEngine.Object)Game.Instance == (UnityEngine.Object)null)
     {
         ToggleExplorer(true);
     }
     disabledPlatformUnlocks.SetActive((UnityEngine.Object)SaveGame.Instance != (UnityEngine.Object)null);
     if ((UnityEngine.Object)SaveGame.Instance != (UnityEngine.Object)null)
     {
         disabledPlatformUnlocks.GetComponent <HierarchyReferences>().GetReference("enabled").gameObject.SetActive(!DebugHandler.InstantBuildMode && !SaveGame.Instance.sandboxEnabled && !Game.Instance.debugWasUsed);
         disabledPlatformUnlocks.GetComponent <HierarchyReferences>().GetReference("disabled").gameObject.SetActive(DebugHandler.InstantBuildMode || SaveGame.Instance.sandboxEnabled || Game.Instance.debugWasUsed);
     }
 }
Exemplo n.º 17
0
 private void SetSelectedGame(string filename, string savename)
 {
     if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
     {
         Debug.LogError("The filename provided is not valid.");
         deleteButton.isInteractable = false;
     }
     else
     {
         deleteButton.isInteractable = true;
         KButton kButton = (selectedFileName == null) ? null : fileButtonMap[selectedFileName];
         if ((UnityEngine.Object)kButton != (UnityEngine.Object)null)
         {
             kButton.GetComponent <ImageToggleState>().SetState(ImageToggleState.State.Inactive);
         }
         selectedFileName = filename;
         FileName.text    = Path.GetFileName(selectedFileName);
         kButton          = fileButtonMap[selectedFileName];
         kButton.GetComponent <ImageToggleState>().SetState(ImageToggleState.State.Active);
         try
         {
             SaveGame.Header   header;
             SaveGame.GameInfo gameInfo = SaveLoader.LoadHeader(filename, out header);
             string            fileName = Path.GetFileName(filename);
             if (gameInfo.isAutoSave)
             {
                 fileName = fileName + "\n" + UI.FRONTEND.LOADSCREEN.AUTOSAVEWARNING;
             }
             CyclesSurvivedValue.text  = gameInfo.numberOfCycles.ToString();
             DuplicantsAliveValue.text = gameInfo.numberOfDuplicants.ToString();
             InfoText.text             = string.Empty;
             if (IsSaveFileFromUnsupportedFutureBuild(header))
             {
                 InfoText.text             = string.Format(UI.FRONTEND.LOADSCREEN.SAVE_TOO_NEW, filename, header.buildVersion, 365655u);
                 loadButton.isInteractable = false;
                 loadButton.GetComponent <ImageToggleState>().SetState(ImageToggleState.State.Disabled);
             }
             else if (gameInfo.saveMajorVersion < 7)
             {
                 InfoText.text             = string.Format(UI.FRONTEND.LOADSCREEN.UNSUPPORTED_SAVE_VERSION, filename, gameInfo.saveMajorVersion, gameInfo.saveMinorVersion, 7, 11);
                 loadButton.isInteractable = false;
                 loadButton.GetComponent <ImageToggleState>().SetState(ImageToggleState.State.Disabled);
             }
             else if (!loadButton.isInteractable)
             {
                 loadButton.isInteractable = true;
                 loadButton.GetComponent <ImageToggleState>().SetState(ImageToggleState.State.Inactive);
             }
             if (InfoText.text == string.Empty && gameInfo.isAutoSave)
             {
                 InfoText.text = UI.FRONTEND.LOADSCREEN.AUTOSAVEWARNING;
             }
         }
         catch (Exception obj)
         {
             Debug.LogWarning(obj);
             InfoText.text = string.Format(UI.FRONTEND.LOADSCREEN.CORRUPTEDSAVE, filename);
             if (loadButton.isInteractable)
             {
                 loadButton.isInteractable = false;
                 loadButton.GetComponent <ImageToggleState>().SetState(ImageToggleState.State.Disabled);
             }
             deleteButton.isInteractable = false;
         }
         try
         {
             Sprite sprite    = RetireColonyUtility.LoadColonyPreview(selectedFileName, savename);
             Image  component = previewImageRoot.GetComponent <Image>();
             component.sprite = sprite;
             component.color  = ((!(bool)sprite) ? Color.black : Color.white);
         }
         catch (Exception obj2)
         {
             Debug.Log(obj2);
         }
     }
 }
Exemplo n.º 18
0
 public string Save(string filename, bool isAutoSave = false, bool updateSavePointer = true)
 {
     KSerialization.Manager.Clear();
     ReportSaveMetrics(isAutoSave);
     RetireColonyUtility.SaveColonySummaryData();
     if (isAutoSave && !GenericGameSettings.instance.keepAllAutosaves)
     {
         List <string> saveFiles = GetSaveFiles(Path.GetDirectoryName(filename));
         for (int num = saveFiles.Count - 1; num >= 9; num--)
         {
             string text = saveFiles[num];
             try
             {
                 Debug.Log("Deleting old autosave: " + text);
                 File.Delete(text);
             }
             catch (Exception ex)
             {
                 Debug.LogWarning("Problem deleting autosave: " + text + "\n" + ex.ToString());
             }
             string text2 = Path.ChangeExtension(text, ".png");
             try
             {
                 if (File.Exists(text2))
                 {
                     File.Delete(text2);
                 }
             }
             catch (Exception ex2)
             {
                 Debug.LogWarning("Problem deleting autosave screenshot: " + text2 + "\n" + ex2.ToString());
             }
         }
     }
     byte[] buffer = null;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (BinaryWriter writer = new BinaryWriter(memoryStream))
         {
             Save(writer);
             buffer = ((!compressSaveData) ? memoryStream.ToArray() : CompressContents(memoryStream.GetBuffer(), (int)memoryStream.Length));
         }
     }
     try
     {
         using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(filename, FileMode.Create)))
         {
             SaveGame.Header header;
             byte[]          saveHeader = SaveGame.Instance.GetSaveHeader(isAutoSave, compressSaveData, out header);
             binaryWriter.Write(header.buildVersion);
             binaryWriter.Write(header.headerSize);
             binaryWriter.Write(header.headerVersion);
             binaryWriter.Write(header.compression);
             binaryWriter.Write(saveHeader);
             KSerialization.Manager.SerializeDirectory(binaryWriter);
             binaryWriter.Write(buffer);
             Stats.Print();
         }
     }
     catch (Exception ex3)
     {
         if (!(ex3 is UnauthorizedAccessException))
         {
             if (!(ex3 is IOException))
             {
                 throw ex3;
             }
             DebugUtil.LogArgs("IOException (probably out of disk space) for " + filename);
             ConfirmDialogScreen confirmDialogScreen = (ConfirmDialogScreen)GameScreenManager.Instance.StartScreen(ScreenPrefabs.Instance.ConfirmDialogScreen.gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject, GameScreenManager.UIRenderTarget.ScreenSpaceOverlay);
             confirmDialogScreen.PopupConfirmDialog(string.Format(UI.CRASHSCREEN.SAVEFAILED, "IOException. You may not have enough free space!"), null, null, null, null, null, null, null, null, true);
             return(GetActiveSaveFilePath());
         }
         DebugUtil.LogArgs("UnauthorizedAccessException for " + filename);
         ConfirmDialogScreen confirmDialogScreen2 = (ConfirmDialogScreen)GameScreenManager.Instance.StartScreen(ScreenPrefabs.Instance.ConfirmDialogScreen.gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject, GameScreenManager.UIRenderTarget.ScreenSpaceOverlay);
         confirmDialogScreen2.PopupConfirmDialog(string.Format(UI.CRASHSCREEN.SAVEFAILED, "Unauthorized Access Exception"), null, null, null, null, null, null, null, null, true);
         return(GetActiveSaveFilePath());
     }
     if (updateSavePointer)
     {
         SetActiveSaveFilePath(filename);
     }
     Game.Instance.timelapser.SaveColonyPreview(filename);
     DebugUtil.LogArgs("Saved to", "[" + filename + "]");
     GC.Collect();
     return(filename);
 }
Exemplo n.º 19
0
    private void UpdateAchievementData(RetiredColonyData data, string[] newlyAchieved = null)
    {
        int   num  = 1;
        float num2 = 1f;

        if (newlyAchieved != null && newlyAchieved.Length > 0)
        {
            this.retiredColonyData = RetireColonyUtility.LoadRetiredColonies(true);
        }
        foreach (KeyValuePair <string, GameObject> achievementEntry in achievementEntries)
        {
            bool flag  = false;
            bool flag2 = false;
            if (data != null)
            {
                string[] achievements = data.achievements;
                foreach (string a in achievements)
                {
                    if (a == achievementEntry.Key)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (!flag && data == null && this.retiredColonyData != null)
            {
                RetiredColonyData[] array = this.retiredColonyData;
                foreach (RetiredColonyData retiredColonyData in array)
                {
                    string[] achievements2 = retiredColonyData.achievements;
                    foreach (string a2 in achievements2)
                    {
                        if (a2 == achievementEntry.Key)
                        {
                            flag2 = true;
                        }
                    }
                }
            }
            bool flag3 = false;
            if (newlyAchieved != null)
            {
                for (int l = 0; l < newlyAchieved.Length; l++)
                {
                    if (newlyAchieved[l] == achievementEntry.Key)
                    {
                        flag3 = true;
                    }
                }
            }
            if (flag || flag3)
            {
                if (flag3)
                {
                    achievementEntry.Value.GetComponent <AchievementWidget>().ActivateNewlyAchievedFlourish(num2 + (float)num * 1f);
                    num++;
                }
                else
                {
                    achievementEntry.Value.GetComponent <AchievementWidget>().SetAchievedNow();
                }
            }
            else if (flag2)
            {
                achievementEntry.Value.GetComponent <AchievementWidget>().SetAchievedBefore();
            }
            else if (data == null)
            {
                achievementEntry.Value.GetComponent <AchievementWidget>().SetNeverAchieved();
            }
            else
            {
                achievementEntry.Value.GetComponent <AchievementWidget>().SetNotAchieved();
            }
        }
        if (newlyAchieved != null && newlyAchieved.Length > 0)
        {
            StartCoroutine(ShowAchievementVeil());
            StartCoroutine(ClearAchievementVeil(num2 + (float)num * 1f));
        }
    }
 public override void OnClick()
 {
     RetireColonyUtility.SaveColonySummaryData();
     MainMenu.ActivateRetiredColoniesScreen(PauseScreen.Instance.transform.parent.gameObject, SaveGame.Instance.BaseName, null);
 }
Exemplo n.º 21
0
    private void OnColonySummary()
    {
        RetiredColonyData currentColonyRetiredColonyData = RetireColonyUtility.GetCurrentColonyRetiredColonyData();

        MainMenu.ActivateRetiredColoniesScreenFromData(Instance.transform.parent.gameObject, currentColonyRetiredColonyData);
    }
Exemplo n.º 22
0
 private void OnRetireConfirm()
 {
     RetireColonyUtility.SaveColonySummaryData();
 }