Beispiel #1
0
        private void StartNewSandbox()
        {
            MyLog.Default.WriteLine("StartNewSandbox - Start");

            GetSettingsFromControls();

            // Load the checkpoint
            ulong checkpointSizeInBytes;
            var   sesionPath = m_scenarioTypesGroup.SelectedButton.UserData as string;

            var checkpoint = MyLocalCache.LoadCheckpoint(sesionPath, out checkpointSizeInBytes);

            if (checkpoint == null)
            {
                return;
            }

            GetSettingsFromControls();
            checkpoint.Settings    = m_settings;
            checkpoint.SessionName = m_nameTextbox.Text;
            checkpoint.Password    = GetPassword();
            checkpoint.Description = GetDescription();
            checkpoint.Mods        = m_mods;

            SetupWorldGeneratorSettings(checkpoint);

            MySessionLoader.LoadSingleplayerSession(
                checkpoint,
                sesionPath,
                checkpointSizeInBytes,
                () =>
            {
                MySession.Static.Save(Path.Combine(MyFileSystem.SavesPath, checkpoint.SessionName.Replace(':', '-')));
            });
        }
Beispiel #2
0
#pragma warning restore 649

        private void DoLoadSession(string sessionPath)
        {
            if (!Path.IsPathRooted(sessionPath))
            {
                sessionPath = Path.Combine(MyFileSystem.SavesPath, sessionPath);
            }

            if (!Sandbox.Engine.Platform.Game.IsDedicated)
            {
                MySessionLoader.LoadSingleplayerSession(sessionPath);
                return;
            }
            ulong checkpointSize;
            MyObjectBuilder_Checkpoint checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out checkpointSize);

            if (MySession.IsCompatibleVersion(checkpoint))
            {
                if (MySteamWorkshop.DownloadWorldModsBlocking(checkpoint.Mods).Success)
                {
                    // MySpaceAnalytics.Instance.SetEntry(MyGameEntryEnum.Load);
                    MySession.Load(sessionPath, checkpoint, checkpointSize);
                    _hostServerForSession(MySession.Static, MyMultiplayer.Static);
                }
                else
                {
                    MyLog.Default.WriteLineAndConsole("Unable to download mods");
                }
            }
            else
            {
                MyLog.Default.WriteLineAndConsole(MyTexts.Get(MyCommonTexts.DialogTextIncompatibleWorldVersion)
                                                  .ToString());
            }
        }
        public override bool Update(bool hasFocus)
        {
            if (!hasFocus)
            {
                return(base.Update(hasFocus));
            }

            if (m_childScreenLaunched && hasFocus)
            {
                CloseScreenNow();
            }

            if (m_childScreenLaunched)
            {
                return(base.Update(hasFocus));
            }

            if (MyInput.Static.IsKeyPress(MyKeys.Escape))
            {
                MySessionLoader.UnloadAndExitToMenu();
                return(base.Update(hasFocus));
            }

            switch (m_quickLaunchType)
            {
            case MyQuickLaunchType.LAST_SANDBOX:
            {
                var lastSessionPath = MyLocalCache.GetLastSessionPath();
                if (lastSessionPath != null && System.IO.Directory.Exists(lastSessionPath))
                {
                    MySessionLoader.LoadSingleplayerSession(lastSessionPath);
                }
                else
                {
                    MySandboxGame.AfterLogos();
                }
                m_childScreenLaunched = true;
            }
            break;

            case MyQuickLaunchType.NEW_SANDBOX:
            {
                QuickstartSandbox(null, null);
                m_childScreenLaunched = true;
            }
            break;

            default:
            {
                throw new InvalidBranchException();
            }
            }

            return(base.Update(hasFocus));
        }
Beispiel #4
0
        public static void DoReload()
        {
            GC.Collect(2, GCCollectionMode.Forced);
            MySandboxGame.Log.WriteLine(String.Format("RELOAD TEST, Menu GC: {0} B", GC.GetTotalMemory(false).ToString("##,#")));
            MySandboxGame.Log.WriteLine(String.Format("RELOAD TEST, Menu WS: {0} B", Process.GetCurrentProcess().PrivateMemorySize64.ToString("##,#")));
            var session = MyLocalCache.GetAvailableWorldInfos().OrderByDescending(s => s.Item2.LastLoadTime).FirstOrDefault();

            if (session != null)
            {
                MySessionLoader.LoadSingleplayerSession(session.Item1);
            }
        }
    public static void DoReload()
    {
        GC.Collect(2, GCCollectionMode.Forced);
        MySandboxGame.Log.WriteLine(string.Format("RELOAD TEST, Menu GC: {0} B", GC.GetTotalMemory(forceFullCollection: false).ToString("##,#")));
        MySandboxGame.Log.WriteLine(string.Format("RELOAD TEST, Menu WS: {0} B", Process.GetCurrentProcess().PrivateMemorySize64.ToString("##,#")));
        Tuple <string, MyWorldInfo> tuple = Enumerable.FirstOrDefault(Enumerable.OrderByDescending(MyLocalCache.GetAvailableWorldInfos(), (Tuple <string, MyWorldInfo> s) => s.Item2.LastSaveTime));

        if (tuple != null)
        {
            MySessionLoader.LoadSingleplayerSession(tuple.Item1);
        }
    }
        private void QuickstartScenario(string scenarioName)
        {
            string path        = "CustomWorlds";
            string sessionPath = Path.Combine(MyFileSystem.ContentPath, path, scenarioName);
            ulong  sizeInBytes;
            MyObjectBuilder_Checkpoint checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out sizeInBytes);

            if (checkpoint != null)
            {
                MySessionLoader.LoadSingleplayerSession(checkpoint, sessionPath, sizeInBytes, delegate
                {
                    MyAsyncSaving.Start(null, Path.Combine(MyFileSystem.SavesPath, checkpoint.SessionName.Replace(':', '-')));
                });
            }
        }
 private void OnSuccess(string sessionPath)
 {
     if (m_currentButton == m_copyButton)
     {
         var loadScreen = new MyGuiScreenLoadSandbox();
         MyGuiSandbox.AddScreen(new MyGuiScreenLoadSandbox());
         // TODO: FIx whatever I broke here
         //loadScreen.SelectSteamWorld(sessionPath);
     }
     else if (m_currentButton == m_loadButton)
     {
         MySessionLoader.LoadSingleplayerSession(sessionPath);
     }
     m_currentButton = null;
 }
Beispiel #8
0
        private void LoadSandbox()
        {
            MyLog.Default.WriteLine("LoadSandbox() - Start");

            var row = m_saveBrowser.SelectedRow;

            if (row != null)
            {
                var saveInfo = m_saveBrowser.GetSave(row);
                if (saveInfo == null || saveInfo.Item2.IsCorrupted)
                {
                    return;
                }
                MySessionLoader.LoadSingleplayerSession(saveInfo.Item1);
            }

            MyLog.Default.WriteLine("LoadSandbox() - End");
        }
Beispiel #9
0
        private void LoadSandbox()
        {
            MyLog.Default.WriteLine("LoadSandbox() - Start");

            var row = m_saveBrowser.SelectedRow;

            if (row != null)
            {
                var saveInfo = row.UserData as FileInfo;
                if (saveInfo == null)
                {
                    return;
                }
                MySessionLoader.LoadSingleplayerSession(saveInfo.DirectoryName);
            }

            MyLog.Default.WriteLine("LoadSandbox() - End");
        }
Beispiel #10
0
#pragma warning restore 649

        private void DoLoadSession(string sessionPath)
        {
            if (!Path.IsPathRooted(sessionPath))
            {
                sessionPath = Path.Combine(MyFileSystem.SavesPath, sessionPath);
            }

            if (!Sandbox.Engine.Platform.Game.IsDedicated)
            {
                MySessionLoader.LoadSingleplayerSession(sessionPath);
                return;
            }
            MyObjectBuilder_Checkpoint checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out ulong checkpointSize);

            /*if (MySession.IsCompatibleVersion(checkpoint))
             * {
             *  var downloadResult = MyWorkshop.DownloadWorldModsBlocking(checkpoint.Mods.Select(b =>
             *  {
             *      b.PublishedServiceName = ModItemUtils.GetDefaultServiceName();
             *      return b;
             *  }).ToList(), null);
             *  if (downloadResult.Success)
             *  {
             *      MyLog.Default.WriteLineAndConsole("Mods Downloaded");
             *      // MySpaceAnalytics.Instance.SetEntry(MyGameEntryEnum.Load);
             *      MySession.Load(sessionPath, checkpoint, checkpointSize);
             *      _hostServerForSession(MySession.Static, MyMultiplayer.Static);
             *  }
             *  else
             *  {
             *      MyLog.Default.WriteLineAndConsole("Unable to download mods");
             *      MyLog.Default.WriteLineAndConsole("Missing Mods:");
             *      downloadResult.MismatchMods?.ForEach(b => MyLog.Default.WriteLineAndConsole($"\t{b.Title} ({b.Id})"));
             *  }
             * }
             * else
             *  MyLog.Default.WriteLineAndConsole(MyTexts.Get(MyCommonTexts.DialogTextIncompatibleWorldVersion)
             *      .ToString());*/
        }
        private void OnEditButtonClick(object sender)
        {
            //run as normal save
            var row = m_scenarioTable.SelectedRow;

            if (row != null)
            {
                var save = FindSave(row);
                if (save != null)
                {
                    CloseScreen();
                    MySessionLoader.LoadSingleplayerSession(save.Item1);
                }
                else
                {
                    Debug.Fail("save not found");
                }
            }
            else
            {
                Debug.Fail("row not found");
            }
        }
Beispiel #12
0
 public void LoadScenario(string scenarioPath)
 {
     Log.WriteLine($"Loading scenario: '{scenarioPath}'");
     MySessionLoader.LoadSingleplayerSession(scenarioPath);
 }
Beispiel #13
0
 public void LoadScenario(string scenarioPath)
 {
     Log.WriteLine($"Loading scenario: '{scenarioPath}'");
     //MySessionLoader.UnloadAndExitToMenu();
     MySessionLoader.LoadSingleplayerSession(scenarioPath);
 }
Beispiel #14
0
        // Starts new session with campaign data
        public void LoadSessionFromActiveCampaign(string relativePath, Action afterLoad = null, string campaignDirectoryName = null)
        {
            var    savePath = relativePath;
            string absolutePath;

            // >> WORLD FILE OPERATIONS
            // Find the existing file in order of modded content to vanilla
            if (m_activeCampaign.IsVanilla)
            {
                absolutePath = Path.Combine(MyFileSystem.ContentPath, savePath);

                if (!MyFileSystem.FileExists(absolutePath))
                {
                    MySandboxGame.Log.WriteLine("ERROR: Missing vanilla world file in campaign: " + m_activeCampaignName);
                    Debug.Fail("ERROR: Missing vanilla world file in campaign: " + m_activeCampaignName);
                    return;
                }
            }
            else
            {
                // Modded content
                absolutePath = Path.Combine(m_activeCampaign.ModFolderPath, savePath);
                // try finding respective vanilla file if the file does not exist
                if (!MyFileSystem.FileExists(absolutePath))
                {
                    absolutePath = Path.Combine(MyFileSystem.ContentPath, savePath);
                    if (!MyFileSystem.FileExists(absolutePath))
                    {
                        MySandboxGame.Log.WriteLine("ERROR: Missing world file in campaign: " + m_activeCampaignName);
                        Debug.Fail("ERROR: Missing world file in campaign: " + m_activeCampaignName);
                        return;
                    }
                }
            }

            // Copy the save and load the session
            if (string.IsNullOrEmpty(campaignDirectoryName))
            {
                campaignDirectoryName = ActiveCampaignName + " " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
            }

            var directory       = new DirectoryInfo(Path.GetDirectoryName(absolutePath));
            var targetDirectory = Path.Combine(MyFileSystem.SavesPath, campaignDirectoryName, directory.Name);

            while (MyFileSystem.DirectoryExists(targetDirectory))
            {
                // Finid new unique name for the folder
                targetDirectory = Path.Combine(MyFileSystem.SavesPath, directory.Name + " " + MyUtils.GetRandomInt(int.MaxValue).ToString("########"));
            }
            MyUtils.CopyDirectory(directory.FullName, targetDirectory);

            // >> LOCALIZATION
            // Set localization for loaded level in the after load event
            if (string.IsNullOrEmpty(m_selectedLanguage))
            {
                m_selectedLanguage = m_activeCampaign.DefaultLocalizationLanguage;

                if (string.IsNullOrEmpty(m_selectedLanguage) && m_activeCampaign.LocalizationLanguages.Count > 0)
                {
                    m_selectedLanguage = m_activeCampaign.LocalizationLanguages[0];
                }
            }

            if (!string.IsNullOrEmpty(m_selectedLanguage))
            {
                // Initilize the sessionComponent in after load event
                afterLoad += () =>
                {
                    var comp = MySession.Static.GetComponent <MyLocalizationSessionComponent>();
                    comp.LoadCampaignLocalization(m_activeCampaign.LocalizationPaths, m_activeCampaign.ModFolderPath);
                    comp.SwitchLanguage(m_selectedLanguage);
                };
            }

            // ATM only single player campaigns are supported
            if (!m_activeCampaign.IsMultiplayer)
            {
                MySessionLoader.LoadSingleplayerSession(targetDirectory, afterLoad);
            }
        }