public void SaveConfig() { DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME)); Log.Info("Saved dedicated config."); try { MyObjectBuilderSerializer.DeserializeXML(Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc"), out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes); if (checkpoint == null) { Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})"); return; } checkpoint.Settings = DedicatedConfig.SessionSettings; checkpoint.Mods.Clear(); foreach (var modId in DedicatedConfig.Model.Mods) { checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId)); } MyLocalCache.SaveCheckpoint(checkpoint, DedicatedConfig.LoadWorld); Log.Info("Saved world config."); } catch (Exception e) { Log.Error("Failed to write sandbox config, changes will not appear on server"); Log.Error(e); } }
protected override void LoadSandboxInternal(Tuple <string, MyWorldInfo> save, bool MP) { base.LoadSandboxInternal(save, MP); if (save.Item1 == WORKSHOP_PATH_TAG) { var scenario = FindWorkshopScenario(save.Item2.WorkshopId.Value); MySteamWorkshop.CreateWorldInstanceAsync(scenario, MySteamWorkshop.MyWorkshopPathInfo.CreateScenarioInfo(), true, delegate(bool success, string sessionPath) { if (success) { //add briefing from workshop description ulong dummy; var checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out dummy); checkpoint.Briefing = save.Item2.Briefing; MyLocalCache.SaveCheckpoint(checkpoint, sessionPath); MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Scenario); MyScenarioSystem.LoadMission(sessionPath, /*m_nameTextbox.Text, m_descriptionTextbox.Text,*/ MP, (MyOnlineModeEnum)m_onlineMode.GetSelectedKey(), (short)m_maxPlayersSlider.Value); } else { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextWorkshopDownloadFailed), messageCaption: MyTexts.Get(MySpaceTexts.ScreenCaptionWorkshop))); } }); } else { MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Scenario); MyScenarioSystem.LoadMission(save.Item1, /*m_nameTextbox.Text, m_descriptionTextbox.Text,*/ MP, (MyOnlineModeEnum)m_onlineMode.GetSelectedKey(), (short)m_maxPlayersSlider.Value); } }
private void saveConfigButton_Click(object sender, EventArgs e) { SaveConfiguration(); if (!string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.LoadWorld) && !MySandboxGame.ConfigDedicated.SessionSettings.Battle) { ulong sizeInBytes; var path = MySandboxGame.ConfigDedicated.LoadWorld; MyObjectBuilder_Checkpoint checkpoint = MyLocalCache.LoadCheckpoint(path, out sizeInBytes); if (!string.IsNullOrWhiteSpace(MySandboxGame.ConfigDedicated.WorldName)) { checkpoint.SessionName = MySandboxGame.ConfigDedicated.WorldName; } checkpoint.Settings = m_selectedSessionSettings; checkpoint.Mods.Clear(); foreach (ulong publishedFileId in MySandboxGame.ConfigDedicated.Mods) { checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(publishedFileId)); } MyLocalCache.SaveCheckpoint(checkpoint, path); } }
private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { string worldName = string.IsNullOrEmpty(WorldName.Text) ? _currentItem.Name : WorldName.Text; var worldPath = Path.Combine(TorchBase.Instance.Config.InstancePath, "Saves", worldName); var checkpoint = _currentItem.Checkpoint; if (Directory.Exists(worldPath)) { MessageBox.Show("World already exists with that name."); return; } Directory.CreateDirectory(worldPath); foreach (var file in Directory.EnumerateFiles(_currentItem.Path, "*", SearchOption.AllDirectories)) { File.Copy(file, Path.Combine(worldPath, file.Replace($"{_currentItem.Path}\\", ""))); } checkpoint.SessionName = worldName; MyLocalCache.SaveCheckpoint(checkpoint, worldPath); _instanceManager.SelectWorld(worldPath, false); _instanceManager.ImportSelectedWorldConfig(); Close(); }
public void SaveConfig() { Config.Save(_configPath); //TODO: make this work try { var checkpoint = MyLocalCache.LoadCheckpoint(_viewModel.LoadWorld, out ulong size); checkpoint.SessionName = _viewModel.WorldName; checkpoint.Settings = _viewModel.SessionSettings; checkpoint.Mods.Clear(); foreach (var modId in _viewModel.Mods) { checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId)); } Debug.Assert(checkpoint != null); Debug.Assert(_viewModel.LoadWorld != null); MyLocalCache.SaveCheckpoint(checkpoint, _viewModel.LoadWorld); } catch (Exception e) { var log = LogManager.GetLogger("Torch"); log.Error("Failed to overwrite sandbox config, changes will not appear on server"); log.Error(e); } }
private void SandboxSectorLoaded(MyMwcVector3Int targetSector, MyMwcObjectBuilder_Checkpoint checkpoint, MyMwcObjectBuilder_Sector cachedSector, MyMwcStartSessionRequestTypeEnum startSessionType, MyMissionID?startMission) { if (checkpoint.SectorObjectBuilder == null) // Server said, use cache { checkpoint.SectorObjectBuilder = cachedSector; } else { MyLocalCache.SaveCheckpoint(checkpoint); } MyGuiScreenGamePlay.ReloadGameplayScreen(checkpoint, startSessionType, MyGuiScreenGamePlayType.GAME_SANDBOX, startMission); }
public MyServerAction SaveLastCheckpoint(bool createChapter = false) { if (MyMultiplayerGameplay.IsRunning && !MyMultiplayerGameplay.Static.IsHost) { return(null); } var lastChapterTime = MyLocalCache.GetLastChapterTimestamp(); var nextChapterTime = lastChapterTime + TimeSpan.FromHours(3); if (MyMissions.ActiveMission == null && DateTime.Now > nextChapterTime) { createChapter = true; } MyMwcSectorIdentifier sectorId = MyGuiScreenGamePlay.Static.GetSectorIdentifier(); if (CanBeSaved(false, sectorId, false)) { var notification = new MyHudNotification.MyNotification(Localization.MyTextsWrapperEnum.SavingSectorToServer, 2500); MyHudNotification.AddNotification(notification); var checkpoint = GetCheckpointBuilder(true); checkpoint.CurrentSector.UserId = MyClientServer.LoggedPlayer.GetUserId(); // Saving players checkpoint if (MySession.PlayerShip != null && checkpoint.PlayerObjectBuilder.ShipObjectBuilder != null) { float refilRatio = 0.5f; var ship = checkpoint.PlayerObjectBuilder.ShipObjectBuilder; ship.ArmorHealth = MathHelper.Clamp(ship.ArmorHealth, refilRatio * MySession.PlayerShip.MaxArmorHealth, MySession.PlayerShip.MaxArmorHealth); ship.ShipHealthRatio = MathHelper.Clamp(ship.ShipHealthRatio, refilRatio, 1.0f); ship.Fuel = MathHelper.Clamp(ship.Fuel, refilRatio * MySession.PlayerShip.MaxFuel, MySession.PlayerShip.MaxFuel); ship.Oxygen = MathHelper.Clamp(ship.Oxygen, refilRatio * MySession.PlayerShip.MaxOxygen, MySession.PlayerShip.MaxOxygen); checkpoint.PlayerObjectBuilder.Health = MathHelper.Clamp(checkpoint.PlayerObjectBuilder.Health, refilRatio * 100, 100); } // Need to store actual checkpoint...because when we travel, we receive only sector, not checkpoint MyGuiScreenGamePlay.Static.AddEnterSectorResponse(checkpoint, null); Debug.Assert(checkpoint.CurrentSector.UserId != null, "Saving last checkpoint as story"); UpdatePlayerStartDummy(checkpoint); MyLocalCache.SaveCheckpoint(checkpoint, createChapter); checkpoint.SectorObjectBuilder = null; // Don't save sector } return(null); }
private void LoadSandbox(bool MP) { MyLog.Default.WriteLine("LoadSandbox() - Start"); var row = m_scenarioTable.SelectedRow; if (row != null) { var save = FindSave(row); if (save != null) { if (save.Item1 == WORKSHOP_PATH_TAG) { var scenario = FindWorkshopScenario(save.Item2.WorkshopId.Value); MySteamWorkshop.CreateWorldInstanceAsync(scenario, MySteamWorkshop.MyWorkshopPathInfo.CreateScenarioInfo(), true, delegate(bool success, string sessionPath) { if (success) { //add briefing from workshop description ulong dummy; var checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out dummy); checkpoint.Briefing = save.Item2.Briefing; MyLocalCache.SaveCheckpoint(checkpoint, sessionPath); LoadMission(sessionPath, m_nameTextbox.Text, m_descriptionTextbox.Text, MP); } else { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextWorkshopDownloadFailed), messageCaption: MyTexts.Get(MySpaceTexts.ScreenCaptionWorkshop))); } }); } else { LoadMission(save.Item1, m_nameTextbox.Text, m_descriptionTextbox.Text, MP); } } } MyLog.Default.WriteLine("LoadSandbox() - End"); }
void SaveAsync(string newSaveName, string sessionPath, MyWorldInfo copyFrom) { // Try a simple path, then a random if it already exists var newSessionPath = MyLocalCache.GetSessionSavesPath(newSaveName, false, false); while (Directory.Exists(newSessionPath)) { newSessionPath = MyLocalCache.GetSessionSavesPath(newSaveName + MyUtils.GetRandomInt(int.MaxValue).ToString("########"), false, false); } Directory.CreateDirectory(newSessionPath); MyUtils.CopyDirectory(sessionPath, newSessionPath); ulong sizeInBytes; var checkpoint = MyLocalCache.LoadCheckpoint(newSessionPath, out sizeInBytes); Debug.Assert(checkpoint != null); checkpoint.SessionName = copyFrom.SessionName; checkpoint.WorkshopId = null; MyLocalCache.SaveCheckpoint(checkpoint, newSessionPath); MyLocalCache.SaveLastLoadedTime(newSessionPath, DateTime.Now); }
private void ChangeWorldSettings() { // Confirm dialog? // Scenario should not be changed from edit settings m_checkpoint.SessionName = m_nameTextbox.Text; m_checkpoint.Description = m_descriptionTextbox.Text; GetSettingsFromControls(); m_checkpoint.Settings = m_settings; m_checkpoint.Mods = m_mods; MyLocalCache.SaveCheckpoint(m_checkpoint, m_sessionPath); if (MySession.Static != null && MySession.Static.Name == m_checkpoint.SessionName && m_sessionPath == MySession.Static.CurrentPath) { var session = MySession.Static; session.Password = GetPassword(); session.Description = GetDescription(); session.Settings = m_checkpoint.Settings; session.Mods = m_checkpoint.Mods; } CloseScreen(); }
private void startButton_Click(object sender, EventArgs e) { saveConfigButton_Click(sender, e); if (!string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.LoadWorld)) { ulong sizeInBytes; var path = MySandboxGame.ConfigDedicated.LoadWorld; MyObjectBuilder_Checkpoint checkpoint = MyLocalCache.LoadCheckpoint(path, out sizeInBytes); if (!string.IsNullOrWhiteSpace(MySandboxGame.ConfigDedicated.WorldName)) { checkpoint.SessionName = MySandboxGame.ConfigDedicated.WorldName; } checkpoint.Settings = m_selectedSessionSettings; checkpoint.Mods.Clear(); foreach (ulong publishedFileId in MySandboxGame.ConfigDedicated.Mods) { checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(publishedFileId)); } MyLocalCache.SaveCheckpoint(checkpoint, path); } if (m_isService) // Service { startService(); } else // Local / Console { Process.Start("SpaceEngineersDedicated.exe", "-console -ignorelastsession"); Close(); } }
void OnPublishButtonClick(MyGuiControlButton sender) { var row = m_scenarioTable.SelectedRow; if (row == null) { return; } if (row.UserData == null) { return; } string fullPath = (string)(((Tuple <string, MyWorldInfo>)row.UserData).Item1); MyWorldInfo worldInfo = FindSave(m_scenarioTable.SelectedRow).Item2; //var mod = (MyObjectBuilder_Checkpoint.ModItem)row.UserData; //var nameSB = m_selectedRow.GetCell(1).Text; //var name = nameSB.ToString(); MyStringId textQuestion, captionQuestion; if (worldInfo.WorkshopId != null) { textQuestion = MySpaceTexts.MessageBoxTextDoYouWishToUpdateScenario; captionQuestion = MySpaceTexts.MessageBoxCaptionDoYouWishToUpdateScenario; } else { textQuestion = MySpaceTexts.MessageBoxTextDoYouWishToPublishScenario; captionQuestion = MySpaceTexts.MessageBoxCaptionDoYouWishToPublishScenario; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum : MyMessageBoxStyleEnum.Info, buttonType : MyMessageBoxButtonsType.YES_NO, messageText : MyTexts.Get(textQuestion), messageCaption : MyTexts.Get(captionQuestion), callback : delegate(MyGuiScreenMessageBox.ResultEnum val) { if (val == MyGuiScreenMessageBox.ResultEnum.YES) { string[] inTags = null; var subscribedItem = GetSubscribedItem(worldInfo.WorkshopId); if (subscribedItem != null) { inTags = subscribedItem.Tags; if (subscribedItem.SteamIDOwner != MySteam.UserId) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextPublishFailed_OwnerMismatchMod),//TODO rename messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionModPublishFailed))); return; } } /*MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_SCENARIO_TAG, MySteamWorkshop.ScenarioCategories, inTags, delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags) * { * if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES) * {*/ MySteamWorkshop.PublishScenarioAsync(fullPath, worldInfo.SessionName, worldInfo.Description, worldInfo.WorkshopId, /*outTags,*/ SteamSDK.PublishedFileVisibility.Public, callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId) //TODO public visibility!! { if (success) { ulong dummy; var checkpoint = MyLocalCache.LoadCheckpoint(fullPath, out dummy); worldInfo.WorkshopId = publishedFileId; checkpoint.WorkshopId = publishedFileId; MyLocalCache.SaveCheckpoint(checkpoint, fullPath); MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum: MyMessageBoxStyleEnum.Info, messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextScenarioPublished), messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionScenarioPublished), callback: (a) => { MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId)); FillList(); })); } else { MyStringId error; switch (result) { case Result.AccessDenied: error = MySpaceTexts.MessageBoxTextPublishFailed_AccessDenied; break; default: error = MySpaceTexts.MessageBoxTextScenarioPublishFailed; break; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(error), messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionModPublishFailed))); } }); /* * } * }));*/ } })); }
public static void Publish(string sessionPath, MyWorldInfo worlInfo) { if (MyFakes.XBOX_PREVIEW) { MyGuiSandbox.Show(MyCommonTexts.MessageBoxTextErrorFeatureNotAvailableYet, MyCommonTexts.MessageBoxCaptionError); return; } MyStringId textQuestion, captionQuestion; if (worlInfo.WorkshopId.HasValue) { textQuestion = MyCommonTexts.MessageBoxTextDoYouWishToUpdateWorld; captionQuestion = MyCommonTexts.MessageBoxCaptionDoYouWishToUpdateWorld; } else { textQuestion = MyCommonTexts.MessageBoxTextDoYouWishToPublishWorld; captionQuestion = MyCommonTexts.MessageBoxCaptionDoYouWishToPublishWorld; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum : MyMessageBoxStyleEnum.Info, buttonType : MyMessageBoxButtonsType.YES_NO, messageText : MyTexts.Get(textQuestion), messageCaption : MyTexts.Get(captionQuestion), callback : delegate(MyGuiScreenMessageBox.ResultEnum val) { if (val == MyGuiScreenMessageBox.ResultEnum.YES) { Action <MyGuiScreenMessageBox.ResultEnum, string[]> onTagsChosen = delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags) { if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES) { MySteamWorkshop.PublishWorldAsync(sessionPath, worlInfo.SessionName, worlInfo.Description, worlInfo.WorkshopId, outTags, SteamSDK.PublishedFileVisibility.Public, callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId) { if (success) { ulong dummy; var checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out dummy); worlInfo.WorkshopId = publishedFileId; checkpoint.WorkshopId = publishedFileId; MyLocalCache.SaveCheckpoint(checkpoint, sessionPath); MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum: MyMessageBoxStyleEnum.Info, messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextWorldPublished), messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWorldPublished), callback: (a) => { MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId)); })); } else { MyStringId error; switch (result) { case Result.AccessDenied: error = MyCommonTexts.MessageBoxTextPublishFailed_AccessDenied; break; default: error = MyCommonTexts.MessageBoxTextWorldPublishFailed; break; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(error), messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWorldPublishFailed))); } }); } }; if (MySteamWorkshop.WorldCategories.Length > 0) { MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_WORLD_TAG, MySteamWorkshop.WorldCategories, null, onTagsChosen)); } else { onTagsChosen(MyGuiScreenMessageBox.ResultEnum.YES, new string[] { MySteamWorkshop.WORKSHOP_WORLD_TAG }); } } })); }
public bool Save() { bool success = true; using (m_savingLock.AcquireExclusiveUsing()) { MySandboxGame.Log.WriteLine("Session snapshot save - START"); using (var indent = MySandboxGame.Log.IndentUsing(LoggingOptions.NONE)) { Debug.Assert(!string.IsNullOrWhiteSpace(TargetDir), "TargetDir should always be correctly set!"); Directory.CreateDirectory(TargetDir); MySandboxGame.Log.WriteLine("Checking file access for files in target dir."); if (!CheckAccessToFiles()) { return(false); } var saveAbsPath = SavingDir; if (Directory.Exists(saveAbsPath)) { Directory.Delete(saveAbsPath, true); } Directory.CreateDirectory(saveAbsPath); try { ulong sectorSizeInBytes = 0; ulong checkpointSizeInBytes = 0; ulong voxelSizeInBytes = 0; success = MyLocalCache.SaveSector(SectorSnapshot, SavingDir, Vector3I.Zero, out sectorSizeInBytes) && MyLocalCache.SaveCheckpoint(CheckpointSnapshot, SavingDir, out checkpointSizeInBytes) && MyLocalCache.SaveLastLoadedTime(TargetDir, DateTime.Now); if (success) { foreach (var entry in CompressedVoxelSnapshots) { voxelSizeInBytes += (ulong)entry.Value.Length; success = success && SaveVoxelSnapshot(entry.Key, entry.Value); } } if (success && Sync.IsServer) { success = MyLocalCache.SaveLastSessionInfo(TargetDir); } if (success) { SavedSizeInBytes = sectorSizeInBytes + checkpointSizeInBytes + voxelSizeInBytes; } } catch (Exception ex) { MySandboxGame.Log.WriteLine("There was an error while saving snapshot."); MySandboxGame.Log.WriteLine(ex); ReportFileError(ex); success = false; } if (success) { HashSet <string> saveFiles = new HashSet <string>(); foreach (var filepath in Directory.GetFiles(saveAbsPath)) { string filename = Path.GetFileName(filepath); var targetFile = Path.Combine(TargetDir, filename); if (File.Exists(targetFile)) { File.Delete(targetFile); } File.Move(filepath, targetFile); saveFiles.Add(filename); } // Clean leftovers from previous saves foreach (var filepath in Directory.GetFiles(TargetDir)) { string filename = Path.GetFileName(filepath); if (saveFiles.Contains(filename) || filename == MyTextConstants.SESSION_THUMB_NAME_AND_EXTENSION) { continue; } File.Delete(filepath); } Directory.Delete(saveAbsPath); //Backup Saves Functionality Backup(); } else { // We don't delete previous save, just the new one. if (Directory.Exists(saveAbsPath)) { Directory.Delete(saveAbsPath, true); } } } MySandboxGame.Log.WriteLine("Session snapshot save - END"); } return(success); }