private static void LoadWorld(MyObjectBuilder_Checkpoint checkpoint, MyObjectBuilder_Sector sector) { Dictionary <ulong, AdminSettingsEnum> AdminSettingsList = (Dictionary <ulong, AdminSettingsEnum>)RemoteAdminSettings.GetValue(MySession.Static); AdminSettingsList.Clear(); MySession.Static.PromotedUsers.Clear(); MySession.Static.CreativeTools.Clear(); MyEntities.MemoryLimitAddFailureReset(); MySession.Static.ElapsedGameTime = new TimeSpan(checkpoint.ElapsedGameTime); MySession.Static.InGameTime = checkpoint.InGameTime; MySession.Static.Name = MyStatControlText.SubstituteTexts(checkpoint.SessionName); MySession.Static.Description = checkpoint.Description; if (checkpoint.PromotedUsers != null) { MySession.Static.PromotedUsers = checkpoint.PromotedUsers.Dictionary; } else { MySession.Static.PromotedUsers = new Dictionary <ulong, MyPromoteLevel>(); } foreach (KeyValuePair <MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player> item in checkpoint.AllPlayersData.Dictionary) { ulong clientId = item.Key.GetClientId(); AdminSettingsEnum adminSettingsEnum = (AdminSettingsEnum)item.Value.RemoteAdminSettings; if (checkpoint.RemoteAdminSettings != null && checkpoint.RemoteAdminSettings.Dictionary.TryGetValue(clientId, out var value)) { adminSettingsEnum = (AdminSettingsEnum)value; } if (!MyPlatformGameSettings.IsIgnorePcuAllowed) { adminSettingsEnum &= ~AdminSettingsEnum.IgnorePcu; adminSettingsEnum &= ~AdminSettingsEnum.KeepOriginalOwnershipOnPaste; } AdminSettingsList[clientId] = adminSettingsEnum; if (!Sync.IsDedicated && clientId == Sync.MyId) { AdminSettings.SetValue(MySession.Static, adminSettingsEnum); //m_adminSettings = adminSettingsEnum; } if (!MySession.Static.PromotedUsers.TryGetValue(clientId, out var value2)) { value2 = MyPromoteLevel.None; } if (item.Value.PromoteLevel > value2) { MySession.Static.PromotedUsers[clientId] = item.Value.PromoteLevel; } if (!MySession.Static.CreativeTools.Contains(clientId) && item.Value.CreativeToolsEnabled) { MySession.Static.CreativeTools.Add(clientId); } } //MySession.Static.WorkshopId = checkpoint.WorkshopId; MySession.Static.Password = checkpoint.Password; MySession.Static.PreviousEnvironmentHostility = checkpoint.PreviousEnvironmentHostility; MySession.Static.RequiresDX = checkpoint.RequiresDX; MySession.Static.CustomLoadingScreenImage = checkpoint.CustomLoadingScreenImage; MySession.Static.CustomLoadingScreenText = checkpoint.CustomLoadingScreenText; MySession.Static.CustomSkybox = checkpoint.CustomSkybox; //FixIncorrectSettings(Settings); // MySession.Static.AppVersionFromSave = checkpoint.AppVersion; //MyToolbarComponent.InitCharacterToolbar(checkpoint.CharacterToolbar); //LoadCameraControllerSettings(checkpoint); SeamlessClient.TryShow("LocalPlayerID: " + MySession.Static.LocalPlayerId); //checkpoint.Gps.Dictionary.TryGetValue(MySession.Static.LocalPlayerId, out MyObjectBuilder_Gps GPSCollection); //SeamlessClient.TryShow("You have " + GPSCollection.Entries.Count + " gps points!"); MySession.Static.Gpss = new MyGpsCollection(); MySession.Static.Gpss.LoadGpss(checkpoint); MyRenderProxy.RebuildCullingStructure(); //MySession.Static.Toolbars.LoadToolbars(checkpoint); Sync.Players.RespawnComponent.InitFromCheckpoint(checkpoint); }
private static MyWorldInfo LoadWorldInfo(string sessionPath) { MyWorldInfo info = null; try { XDocument document = null; string path = Path.Combine(sessionPath, "Sandbox.sbc"); if (File.Exists(path)) { ulong num; info = new MyWorldInfo(); using (Stream stream = MyFileSystem.OpenRead(path).UnwrapGZip()) { document = XDocument.Load(stream); } XElement root = document.Root; XElement element2 = root.Element("SessionName"); XElement element3 = root.Element("Description"); XElement element4 = root.Element("LastSaveTime"); root.Element("WorldID"); XElement element5 = root.Element("WorkshopId"); XElement element6 = root.Element("Briefing"); XElement element1 = root.Element("Settings"); XElement element7 = (element1 != null) ? root.Element("Settings").Element("ScenarioEditMode") : null; XElement element8 = (element1 != null) ? root.Element("Settings").Element("ExperimentalMode") : null; if (element8 != null) { bool.TryParse(element8.Value, out info.IsExperimental); } if (element2 != null) { info.SessionName = MyStatControlText.SubstituteTexts(element2.Value, null); } if (element3 != null) { info.Description = element3.Value; } if (element4 != null) { DateTime.TryParse(element4.Value, out info.LastSaveTime); } if ((element5 != null) && ulong.TryParse(element5.Value, out num)) { info.WorkshopId = new ulong?(num); } if (element6 != null) { info.Briefing = element6.Value; } if (element7 != null) { bool.TryParse(element7.Value, out info.ScenarioEditMode); } } else { return(null); } } catch (Exception exception) { MySandboxGame.Log.WriteLine(exception); info.IsCorrupted = true; } return(info); }
public void LoadWorldInfo() { var filename = Path.Combine(Savepath, SpaceEngineersConsts.SandBoxCheckpointFilename); if (!File.Exists(filename)) { IsValid = false; SessionName = Res.ErrorInvalidSaveLabel; return; } try { XDocument doc; using (var stream = MyFileSystem.OpenRead(filename).UnwrapGZip()) { doc = XDocument.Load(stream); } var root = doc.Root; if (root == null) { IsValid = true; SessionName = Res.ErrorInvalidSaveLabel; return; } var session = root.Element("SessionName"); var lastSaveTime = root.Element("LastSaveTime"); var workshopId = root.Element("WorkshopId"); var appVersion = root.Element("AppVersion"); if (session != null) { SessionName = MyStatControlText.SubstituteTexts(session.Value); } DateTime tempDateTime; if (lastSaveTime != null && DateTime.TryParse(lastSaveTime.Value, out tempDateTime)) { LastSaveTime = tempDateTime; } else { LastSaveTime = DateTime.MinValue; } ulong tmp; if (workshopId != null && ulong.TryParse(workshopId.Value, out tmp)) { WorkshopId = tmp; } if (appVersion == null || appVersion.Value == "0") { Version = new Version(); } else { try { string str = appVersion.Value.Substring(0, appVersion.Value.Length - 6) + "." + appVersion.Value.Substring(appVersion.Value.Length - 6, 3) + "." + appVersion.Value.Substring(appVersion.Value.Length - 3); Version = new Version(str); } catch { Version = new Version(); } } IsValid = true; } catch { IsValid = false; SessionName = Res.ErrorInvalidSaveLabel; } }
private void SetWorldSettings() { //MyEntities.MemoryLimitAddFailureReset(); //Clear old list MySession.Static.PromotedUsers.Clear(); MySession.Static.CreativeTools.Clear(); Dictionary <ulong, AdminSettingsEnum> AdminSettingsList = (Dictionary <ulong, AdminSettingsEnum>)Patches.RemoteAdminSettings.GetValue(MySession.Static); AdminSettingsList.Clear(); // Set new world settings MySession.Static.Name = MyStatControlText.SubstituteTexts(TargetWorld.Checkpoint.SessionName); MySession.Static.Description = TargetWorld.Checkpoint.Description; MySession.Static.Mods = TargetWorld.Checkpoint.Mods; MySession.Static.Settings = TargetWorld.Checkpoint.Settings; MySession.Static.CurrentPath = MyLocalCache.GetSessionSavesPath(MyUtils.StripInvalidChars(TargetWorld.Checkpoint.SessionName), contentFolder: false, createIfNotExists: false); MySession.Static.WorldBoundaries = TargetWorld.Checkpoint.WorldBoundaries; MySession.Static.InGameTime = MyObjectBuilder_Checkpoint.DEFAULT_DATE; MySession.Static.ElapsedGameTime = new TimeSpan(TargetWorld.Checkpoint.ElapsedGameTime); MySession.Static.Settings.EnableSpectator = false; MySession.Static.Password = TargetWorld.Checkpoint.Password; MySession.Static.PreviousEnvironmentHostility = TargetWorld.Checkpoint.PreviousEnvironmentHostility; MySession.Static.RequiresDX = TargetWorld.Checkpoint.RequiresDX; MySession.Static.CustomLoadingScreenImage = TargetWorld.Checkpoint.CustomLoadingScreenImage; MySession.Static.CustomLoadingScreenText = TargetWorld.Checkpoint.CustomLoadingScreenText; MySession.Static.CustomSkybox = TargetWorld.Checkpoint.CustomSkybox; MySession.Static.Gpss = new MyGpsCollection(); MySession.Static.Gpss.LoadGpss(TargetWorld.Checkpoint); MyRenderProxy.RebuildCullingStructure(); //MySession.Static.Toolbars.LoadToolbars(checkpoint); Sync.Players.RespawnComponent.InitFromCheckpoint(TargetWorld.Checkpoint); // Set new admin settings if (TargetWorld.Checkpoint.PromotedUsers != null) { MySession.Static.PromotedUsers = TargetWorld.Checkpoint.PromotedUsers.Dictionary; } else { MySession.Static.PromotedUsers = new Dictionary <ulong, MyPromoteLevel>(); } foreach (KeyValuePair <MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player> item in TargetWorld.Checkpoint.AllPlayersData.Dictionary) { ulong clientId = item.Key.GetClientId(); AdminSettingsEnum adminSettingsEnum = (AdminSettingsEnum)item.Value.RemoteAdminSettings; if (TargetWorld.Checkpoint.RemoteAdminSettings != null && TargetWorld.Checkpoint.RemoteAdminSettings.Dictionary.TryGetValue(clientId, out var value)) { adminSettingsEnum = (AdminSettingsEnum)value; } if (!MyPlatformGameSettings.IsIgnorePcuAllowed) { adminSettingsEnum &= ~AdminSettingsEnum.IgnorePcu; adminSettingsEnum &= ~AdminSettingsEnum.KeepOriginalOwnershipOnPaste; } AdminSettingsList[clientId] = adminSettingsEnum; if (!Sync.IsDedicated && clientId == Sync.MyId) { Patches.AdminSettings.SetValue(MySession.Static, adminSettingsEnum); //m_adminSettings = adminSettingsEnum; } if (!MySession.Static.PromotedUsers.TryGetValue(clientId, out var value2)) { value2 = MyPromoteLevel.None; } if (item.Value.PromoteLevel > value2) { MySession.Static.PromotedUsers[clientId] = item.Value.PromoteLevel; } if (!MySession.Static.CreativeTools.Contains(clientId) && item.Value.CreativeToolsEnabled) { MySession.Static.CreativeTools.Add(clientId); } } }