public static bool CanLoadSave()
    {
        bool   flag = true;
        string activeSaveFilePath = SaveLoader.GetActiveSaveFilePath();

        flag = WorldGen.CanLoad(activeSaveFilePath);
        if (!flag)
        {
            SaveLoader.SetActiveSaveFilePath(null);
            flag = WorldGen.CanLoad(WorldGen.SIM_SAVE_FILENAME);
        }
        return(flag);
    }
Example #2
0
        /// <summary>
        /// Gets the path to the current autosave folder.
        /// </summary>
        /// <returns>The location where autosaves are saved.</returns>
        private static string GetActiveAutoSavePath()
        {
            string filename = SaveLoader.GetActiveSaveFilePath();
            bool   flag     = filename == null;
            string result;

            if (flag)
            {
                result = SaveLoader.GetAutoSavePrefix();
            }
            else
            {
                string root = Path.GetDirectoryName(filename);
                result = Path.Combine(root, "auto_save");
            }
            return(result);
        }
Example #3
0
    private void OnSave()
    {
        string filename = SaveLoader.GetActiveSaveFilePath();

        if (!string.IsNullOrEmpty(filename) && File.Exists(filename))
        {
            base.gameObject.SetActive(false);
            ConfirmDialogScreen confirmDialogScreen = (ConfirmDialogScreen)GameScreenManager.Instance.StartScreen(ScreenPrefabs.Instance.ConfirmDialogScreen.gameObject, base.transform.parent.gameObject, GameScreenManager.UIRenderTarget.ScreenSpaceOverlay);
            confirmDialogScreen.PopupConfirmDialog(string.Format(UI.FRONTEND.SAVESCREEN.OVERWRITEMESSAGE, Path.GetFileNameWithoutExtension(filename)), delegate
            {
                DoSave(filename);
                base.gameObject.SetActive(true);
            }, OnCancelPopup, null, null, null, null, null, null, true);
        }
        else
        {
            OnSaveAs();
        }
    }
    private void DoAutoSave(int day)
    {
        if (!GenericGameSettings.instance.disableAutosave)
        {
            day++;
            newDayMetric[NewCycleKey] = day;
            ThreadedHttps <KleiMetrics> .Instance.SendEvent(newDayMetric);

            string text = SaveLoader.GetActiveSaveFilePath();
            if (text == null)
            {
                text = SaveLoader.GetAutosaveFilePath();
            }
            int num = text.LastIndexOf("\\");
            if (num > 0)
            {
                int num2 = text.IndexOf(" Cycle ", num);
                if (num2 > 0)
                {
                    text = text.Substring(0, num2);
                }
            }
            text = text.Replace(".sav", string.Empty);
            text = text + " Cycle " + day.ToString();
            text = SaveScreen.GetValidSaveFilename(text);
            string autoSavePrefix = SaveLoader.GetAutoSavePrefix();
            text = Path.Combine(autoSavePrefix, Path.GetFileName(text));
            string text2 = text;
            int    num3  = 1;
            while (File.Exists(text))
            {
                text = text2.Replace(".sav", string.Empty);
                text = SaveScreen.GetValidSaveFilename(text2 + " (" + num3 + ")");
                num3++;
            }
            Game.Instance.StartDelayedSave(text, true, false);
        }
    }
        private static void WriteData(int day, ReportData data)
        {
            string reportsPath      = System.Reflection.Assembly.GetAssembly(typeof(ExportDailyReports_OptionsMenuScreen_OnPrefabInit)).Location;
            string reportsFile      = Path.Combine(Path.GetDirectoryName(SaveLoader.GetActiveSaveFilePath()), Path.GetFileNameWithoutExtension(SaveLoader.GetActiveSaveFilePath()) + "_" + day + "_General" + ".csv");
            string reportsPowerFile = Path.Combine(Path.GetDirectoryName(SaveLoader.GetActiveSaveFilePath()), Path.GetFileNameWithoutExtension(SaveLoader.GetActiveSaveFilePath()) + "_" + day + "_Power" + ".csv");

            try
            {
                WriteCSV(reportsFile, data.dataGeneral, data.headersGeneral);

                WriteCSV(reportsPowerFile, data.dataPower, data.headersPower);

                InfoDialogScreen infoDialogScreen = (InfoDialogScreen)GameScreenManager.Instance.StartScreen(ScreenPrefabs.Instance.InfoDialogScreen.gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject);
                infoDialogScreen.SetHeader("Export Daily Reports").AddPlainText("Daily reports exported.");
                infoDialogScreen.Show();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                InfoDialogScreen infoDialogScreen = (InfoDialogScreen)GameScreenManager.Instance.StartScreen(ScreenPrefabs.Instance.InfoDialogScreen.gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject);
                infoDialogScreen.SetHeader("Export Daily Reports").AddPlainText("Error exporting daily reports:\n" + e.ToString());
                infoDialogScreen.Show();
            }
        }
    public void OnKeyDown(KButtonEvent e)
    {
        if (!enabled)
        {
            return;
        }
        if (e.TryConsume(Action.DebugSpawnMinion))
        {
            SpawnMinion();
        }
        else if (e.TryConsume(Action.DebugSpawnStressTest))
        {
            for (int i = 0; i < 60; i++)
            {
                SpawnMinion();
            }
        }
        else if (e.TryConsume(Action.DebugSuperTestMode))
        {
            if (!superTestMode)
            {
                Time.timeScale = 15f;
                superTestMode  = true;
            }
            else
            {
                Time.timeScale = 1f;
                superTestMode  = false;
            }
        }
        else if (e.TryConsume(Action.DebugUltraTestMode))
        {
            if (!ultraTestMode)
            {
                Time.timeScale = 30f;
                ultraTestMode  = true;
            }
            else
            {
                Time.timeScale = 1f;
                ultraTestMode  = false;
            }
        }
        else if (e.TryConsume(Action.DebugSlowTestMode))
        {
            if (!slowTestMode)
            {
                Time.timeScale = 0.06f;
                slowTestMode   = true;
            }
            else
            {
                Time.timeScale = 1f;
                slowTestMode   = false;
            }
        }
        else if (e.TryConsume(Action.DebugDig))
        {
            int mouseCell = GetMouseCell();
            SimMessages.Dig(mouseCell, -1);
        }
        else if (e.TryConsume(Action.DebugInstantBuildMode))
        {
            InstantBuildMode = !InstantBuildMode;
            if ((UnityEngine.Object)Game.Instance == (UnityEngine.Object)null)
            {
                return;
            }
            if ((UnityEngine.Object)PlanScreen.Instance != (UnityEngine.Object)null)
            {
                PlanScreen.Instance.Refresh();
            }
            if ((UnityEngine.Object)BuildMenu.Instance != (UnityEngine.Object)null)
            {
                BuildMenu.Instance.Refresh();
            }
            if ((UnityEngine.Object)OverlayMenu.Instance != (UnityEngine.Object)null)
            {
                OverlayMenu.Instance.Refresh();
            }
            if ((UnityEngine.Object)ConsumerManager.instance != (UnityEngine.Object)null)
            {
                ConsumerManager.instance.RefreshDiscovered(null);
            }
            if ((UnityEngine.Object)ManagementMenu.Instance != (UnityEngine.Object)null)
            {
                ManagementMenu.Instance.CheckResearch(null);
                ManagementMenu.Instance.CheckSkills(null);
                ManagementMenu.Instance.CheckStarmap(null);
            }
            Game.Instance.Trigger(1594320620, "all_the_things");
        }
        else if (e.TryConsume(Action.DebugExplosion))
        {
            Vector3 mousePos = KInputManager.GetMousePos();
            Vector3 position = Camera.main.transform.GetPosition();
            mousePos.z = 0f - position.z - Grid.CellSizeInMeters;
            Vector3 explosion_pos = Camera.main.ScreenToWorldPoint(mousePos);
            GameUtil.CreateExplosion(explosion_pos);
        }
        else if (e.TryConsume(Action.DebugLockCursor))
        {
            if (GenericGameSettings.instance.developerDebugEnable)
            {
                KInputManager.isMousePosLocked = !KInputManager.isMousePosLocked;
                KInputManager.lockedMousePos   = KInputManager.GetMousePos();
            }
        }
        else if (e.TryConsume(Action.DebugDiscoverAllElements))
        {
            if ((UnityEngine.Object)WorldInventory.Instance != (UnityEngine.Object)null)
            {
                foreach (Element element in ElementLoader.elements)
                {
                    WorldInventory.Instance.Discover(element.tag, element.GetMaterialCategoryTag());
                }
            }
        }
        else if (e.TryConsume(Action.DebugToggleUI))
        {
            ToggleScreenshotMode();
        }
        else if (e.TryConsume(Action.SreenShot1x))
        {
            string filename = Path.ChangeExtension(SaveLoader.GetActiveSaveFilePath(), ".png");
            ScreenCapture.CaptureScreenshot(filename, 1);
        }
        else if (e.TryConsume(Action.SreenShot2x))
        {
            string filename2 = Path.ChangeExtension(SaveLoader.GetActiveSaveFilePath(), ".png");
            ScreenCapture.CaptureScreenshot(filename2, 2);
        }
        else if (e.TryConsume(Action.SreenShot8x))
        {
            string filename3 = Path.ChangeExtension(SaveLoader.GetActiveSaveFilePath(), ".png");
            ScreenCapture.CaptureScreenshot(filename3, 8);
        }
        else if (e.TryConsume(Action.SreenShot32x))
        {
            string filename4 = Path.ChangeExtension(SaveLoader.GetActiveSaveFilePath(), ".png");
            ScreenCapture.CaptureScreenshot(filename4, 32);
        }
        else if (e.TryConsume(Action.DebugCellInfo))
        {
            DebugCellInfo = !DebugCellInfo;
        }
        else if (e.TryConsume(Action.DebugToggle))
        {
            if ((UnityEngine.Object)Game.Instance != (UnityEngine.Object)null)
            {
                Game.Instance.UpdateGameActiveRegion(0, 0, Grid.WidthInCells, Grid.HeightInCells);
                SaveGame.Instance.worldGenSpawner.SpawnEverything();
            }
            if ((UnityEngine.Object)DebugPaintElementScreen.Instance != (UnityEngine.Object)null)
            {
                bool activeSelf = DebugPaintElementScreen.Instance.gameObject.activeSelf;
                DebugPaintElementScreen.Instance.gameObject.SetActive(!activeSelf);
                if ((bool)DebugElementMenu.Instance && DebugElementMenu.Instance.root.activeSelf)
                {
                    DebugElementMenu.Instance.root.SetActive(false);
                }
                DebugBaseTemplateButton.Instance.gameObject.SetActive(!activeSelf);
                PropertyTextures.FogOfWarScale = (float)((!activeSelf) ? 1 : 0);
                if ((UnityEngine.Object)CameraController.Instance != (UnityEngine.Object)null)
                {
                    CameraController.Instance.EnableFreeCamera(!activeSelf);
                }
            }
        }
        else if (e.TryConsume(Action.DebugCollectGarbage))
        {
            GC.Collect();
        }
        else if (e.TryConsume(Action.DebugInvincible))
        {
            InvincibleMode = !InvincibleMode;
        }
        else if (e.TryConsume(Action.DebugVisualTest))
        {
            Scenario.Instance.SetupVisualTest();
        }
        else if (e.TryConsume(Action.DebugGameplayTest))
        {
            Scenario.Instance.SetupGameplayTest();
        }
        else if (e.TryConsume(Action.DebugElementTest))
        {
            Scenario.Instance.SetupElementTest();
        }
        else if (e.TryConsume(Action.ToggleProfiler))
        {
            Sim.SIM_HandleMessage(-409964931, 0, null);
        }
        else if (e.TryConsume(Action.DebugRefreshNavCell))
        {
            Pathfinding.Instance.RefreshNavCell(GetMouseCell());
        }
        else if (e.TryConsume(Action.DebugToggleSelectInEditor))
        {
            SetSelectInEditor(!SelectInEditor);
        }
        else if (e.TryConsume(Action.DebugGotoTarget))
        {
            Debug.Log("Debug GoTo");
            Game.Instance.Trigger(775300118, null);
            foreach (Brain item in Components.Brains.Items)
            {
                item.GetSMI <DebugGoToMonitor.Instance>()?.GoToCursor();
                item.GetSMI <CreatureDebugGoToMonitor.Instance>()?.GoToCursor();
            }
        }
        else if (e.TryConsume(Action.DebugTeleport))
        {
            if ((UnityEngine.Object)SelectTool.Instance == (UnityEngine.Object)null)
            {
                return;
            }
            KSelectable selected = SelectTool.Instance.selected;
            if ((UnityEngine.Object)selected != (UnityEngine.Object)null)
            {
                int mouseCell2 = GetMouseCell();
                if (!Grid.IsValidBuildingCell(mouseCell2))
                {
                    PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Negative, UI.DEBUG_TOOLS.INVALID_LOCATION, null, GetMousePos(), 1.5f, false, true);
                    return;
                }
                selected.transform.SetPosition(Grid.CellToPosCBC(mouseCell2, Grid.SceneLayer.Move));
            }
        }
        else if (!e.TryConsume(Action.DebugPlace) && !e.TryConsume(Action.DebugSelectMaterial))
        {
            if (e.TryConsume(Action.DebugNotification))
            {
                if (GenericGameSettings.instance.developerDebugEnable)
                {
                    Tutorial.Instance.DebugNotification();
                }
            }
            else if (e.TryConsume(Action.DebugNotificationMessage))
            {
                if (GenericGameSettings.instance.developerDebugEnable)
                {
                    Tutorial.Instance.DebugNotificationMessage();
                }
            }
            else if (e.TryConsume(Action.DebugSuperSpeed))
            {
                if ((UnityEngine.Object)SpeedControlScreen.Instance != (UnityEngine.Object)null)
                {
                    SpeedControlScreen.Instance.ToggleRidiculousSpeed();
                }
            }
            else if (e.TryConsume(Action.DebugGameStep))
            {
                if ((UnityEngine.Object)SpeedControlScreen.Instance != (UnityEngine.Object)null)
                {
                    SpeedControlScreen.Instance.DebugStepFrame();
                }
            }
            else if (e.TryConsume(Action.DebugSimStep))
            {
                Game.Instance.ForceSimStep();
            }
            else if (e.TryConsume(Action.DebugToggleMusic))
            {
                AudioDebug.Get().ToggleMusic();
            }
            else if (e.TryConsume(Action.DebugRiverTest))
            {
                Scenario.Instance.SetupRiverTest();
            }
            else if (e.TryConsume(Action.DebugTileTest))
            {
                Scenario.Instance.SetupTileTest();
            }
            else if (e.TryConsume(Action.DebugForceLightEverywhere))
            {
                PropertyTextures.instance.ForceLightEverywhere = !PropertyTextures.instance.ForceLightEverywhere;
            }
            else if (e.TryConsume(Action.DebugPathFinding))
            {
                DebugPathFinding = !DebugPathFinding;
                Debug.Log("DebugPathFinding=" + DebugPathFinding);
            }
            else if (!e.TryConsume(Action.DebugFocus))
            {
                if (e.TryConsume(Action.DebugReportBug))
                {
                    if (GenericGameSettings.instance.developerDebugEnable)
                    {
                        int    num = 0;
                        string validSaveFilename;
                        while (true)
                        {
                            validSaveFilename = SaveScreen.GetValidSaveFilename("bug_report_savefile_" + num.ToString());
                            if (!File.Exists(validSaveFilename))
                            {
                                break;
                            }
                            num++;
                        }
                        string save_file = "No save file (front end)";
                        if ((UnityEngine.Object)SaveLoader.Instance != (UnityEngine.Object)null)
                        {
                            save_file = SaveLoader.Instance.Save(validSaveFilename, false, false);
                        }
                        KCrashReporter.ReportBug("Bug Report", save_file);
                    }
                    else
                    {
                        Debug.Log("Debug crash keys are not enabled.");
                    }
                }
                else if (e.TryConsume(Action.DebugTriggerException))
                {
                    if (GenericGameSettings.instance.developerDebugEnable)
                    {
                        string     str        = Guid.NewGuid().ToString();
                        StackTrace stackTrace = new StackTrace(1, true);
                        str = str + "\n" + stackTrace.ToString();
                        KCrashReporter.ReportError("Debug crash with random stack", str, null, ScreenPrefabs.Instance.ConfirmDialogScreen, string.Empty);
                    }
                }
                else if (e.TryConsume(Action.DebugTriggerError))
                {
                    if (GenericGameSettings.instance.developerDebugEnable)
                    {
                        Debug.LogError("Oooops! Testing error!");
                    }
                }
                else if (e.TryConsume(Action.DebugDumpGCRoots))
                {
                    GarbageProfiler.DebugDumpRootItems();
                }
                else if (e.TryConsume(Action.DebugDumpGarbageReferences))
                {
                    GarbageProfiler.DebugDumpGarbageStats();
                }
                else if (e.TryConsume(Action.DebugDumpEventData))
                {
                    if (GenericGameSettings.instance.developerDebugEnable)
                    {
                        KObjectManager.Instance.DumpEventData();
                    }
                }
                else if (e.TryConsume(Action.DebugDumpSceneParitionerLeakData))
                {
                    if (!GenericGameSettings.instance.developerDebugEnable)
                    {
                        goto IL_0b5e;
                    }
                }
                else if (e.TryConsume(Action.DebugCrashSim))
                {
                    if (GenericGameSettings.instance.developerDebugEnable)
                    {
                        Sim.SIM_DebugCrash();
                    }
                }
                else if (e.TryConsume(Action.DebugNextCall))
                {
                    DebugNextCall = true;
                }
                else if (e.TryConsume(Action.DebugTogglePersonalPriorityComparison))
                {
                    Chore.ENABLE_PERSONAL_PRIORITIES = !Chore.ENABLE_PERSONAL_PRIORITIES;
                }
            }
        }
        goto IL_0b5e;
IL_0b5e:
        if (e.Consumed && (UnityEngine.Object)Game.Instance != (UnityEngine.Object)null)
        {
            Game.Instance.debugWasUsed  = true;
            KCrashReporter.debugWasUsed = true;
        }
    }
Example #7
0
    public byte[] GetSaveHeader(bool isAutoSave, bool isCompressed, out Header header)
    {
        string text = null;

        text = ((!isAutoSave) ? JsonConvert.SerializeObject(new GameInfo(GameClock.Instance.GetCycle(), Components.LiveMinionIdentities.Count, baseName, false)) : JsonConvert.SerializeObject(new GameInfo(GameClock.Instance.GetCycle(), Components.LiveMinionIdentities.Count, baseName, true, SaveLoader.GetActiveSaveFilePath(), false)));
        byte[] bytes = Encoding.UTF8.GetBytes(text);
        header = default(Header);
        header.buildVersion  = 365655u;
        header.headerSize    = bytes.Length;
        header.headerVersion = 1u;
        header.compression   = (isCompressed ? 1 : 0);
        return(bytes);
    }
Example #8
0
        public static ConfigObject ReadConfig()
        {
            string savePath = SaveLoader.GetActiveSaveFilePath();

            if (savePath == "")
            {
                return(null);
            }
            FileInfo      file       = new FileInfo(savePath);
            DirectoryInfo saveFolder = file.Directory;

            if (saveFolder == null)
            {
                return(null);
            }
            DirectoryInfo rootFolder   = null;
            DirectoryInfo modFolder    = null;
            DirectoryInfo steamFolder  = null;
            DirectoryInfo targetFolder = null;

            rootFolder = saveFolder.Parent;
            if (rootFolder == null)
            {
                return(null);
            }

            if (rootFolder.Name == "save_files")
            {
                rootFolder = saveFolder.Parent;
            }

            if (rootFolder == null)
            {
                return(null);
            }

            foreach (DirectoryInfo d in rootFolder.GetDirectories())
            {
                if (d.Name == "mods")
                {
                    modFolder = d;
                    break;
                }
            }

            if (modFolder == null)
            {
                return(null);
            }
            foreach (DirectoryInfo d in modFolder.GetDirectories())
            {
                if (d.Name == "Steam")
                {
                    steamFolder = d;
                    break;
                }
            }

            if (steamFolder == null)
            {
                return(null);
            }
            foreach (DirectoryInfo d in steamFolder.GetDirectories())
            {
                if (d.Name == SteamModID)
                {
                    targetFolder = d;
                    break;
                }
            }

            if (targetFolder == null)
            {
                return(null);
            }
            try
            {
                FileInfo target = null;
                foreach (FileInfo f in targetFolder.GetFiles())
                {
                    if ($"{f.Name}".ToLower() == "config.json")
                    {
                        target = f;
                        break;
                    }
                }
                if (target != null)
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.NullValueHandling = NullValueHandling.Ignore;
                    using (StreamReader sr = new StreamReader(target.FullName))
                        using (JsonReader reader = new JsonTextReader(sr))
                        {
                            object _result = serializer.Deserialize <ConfigObject>(reader);
                            return((ConfigObject)_result);
                        }
                }
                else
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.NullValueHandling = NullValueHandling.Ignore;
                    using (StreamWriter sw = new StreamWriter(targetFolder.FullName + @"/config.json"))
                        using (JsonWriter writer = new JsonTextWriter(sw))
                        {
                            ConfigObject co = new ConfigObject();
                            co.LifeSpanOption = 2;
                            co.DieOfOldAge    = true;
                            serializer.Serialize(writer, co);
                            return(co);
                        }
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }