public static XDocument LoadGameSessionDoc(string filePath) { string tempPath = Path.Combine(SaveFolder, "temp"); try { DecompressToDirectory(filePath, tempPath, null); } catch { return(null); } return(XMLExtensions.TryLoadXml(Path.Combine(tempPath, "gamesession.xml"))); }
public static void LoadAll(IEnumerable <string> filePaths) { if (GameSettings.VerboseLogging) { DebugConsole.Log("Loading item prefabs: "); } foreach (string filePath in filePaths) { if (GameSettings.VerboseLogging) { DebugConsole.Log("*** " + filePath + " ***"); } XDocument doc = XMLExtensions.TryLoadXml(filePath); if (doc?.Root == null) { return; } if (doc.Root.Name.ToString().ToLowerInvariant() == "items") { foreach (XElement element in doc.Root.Elements()) { new ItemPrefab(element, filePath); } } else { new ItemPrefab(doc.Root, filePath); } } //initialize item requirements for fabrication recipes //(has to be done after all the item prefabs have been loaded, because the //recipe ingredients may not have been loaded yet when loading the prefab) foreach (MapEntityPrefab me in List) { if (!(me is ItemPrefab itemPrefab)) { continue; } foreach (XElement fabricationRecipe in itemPrefab.fabricationRecipeElements) { itemPrefab.FabricationRecipes.Add(new FabricationRecipe(fabricationRecipe, itemPrefab)); } } }
private static void LoadConfig(string configPath) { try { XDocument doc = XMLExtensions.TryLoadXml(configPath); if (doc == null) { return; } var mainElement = doc.Root; if (doc.Root.IsOverride()) { mainElement = doc.Root.FirstElement(); DebugConsole.NewMessage($"Overriding all level object prefabs with '{configPath}'", Color.Yellow); List.Clear(); } else if (List.Any()) { DebugConsole.Log($"Loading additional level object prefabs from file '{configPath}'"); } foreach (XElement subElement in mainElement.Elements()) { var element = subElement.IsOverride() ? subElement.FirstElement() : subElement; string identifier = element.GetAttributeString("identifier", ""); var existingPrefab = List.Find(p => p.Identifier.Equals(identifier, StringComparison.OrdinalIgnoreCase)); if (existingPrefab != null) { if (subElement.IsOverride()) { DebugConsole.NewMessage($"Overriding the existing level object prefab '{identifier}' using the file '{configPath}'", Color.Yellow); List.Remove(existingPrefab); } else { DebugConsole.ThrowError($"Error in '{configPath}': Duplicate level object prefab '{identifier}' found in '{configPath}'! Each level object prefab must have a unique identifier. " + "Use <override></override> tags to override prefabs."); continue; } } List.Add(new LevelObjectPrefab(element)); } } catch (Exception e) { DebugConsole.ThrowError(string.Format("Failed to load LevelObject prefabs from {0}", configPath), e); } }
public static void LoadFromFile(ContentFile file) { DebugConsole.Log("Loading talent prefab: " + file.Path); RemoveByFile(file.Path); XDocument doc = XMLExtensions.TryLoadXml(file.Path); if (doc == null) { return; } var rootElement = doc.Root; switch (rootElement.Name.ToString().ToLowerInvariant()) { case "talent": TalentPrefabs.Add(new TalentPrefab(rootElement, file.Path), false); break; case "talents": foreach (var element in rootElement.Elements()) { if (element.IsOverride()) { var itemElement = element.GetChildElement("talent"); if (itemElement != null) { TalentPrefabs.Add(new TalentPrefab(rootElement, file.Path), true); } else { DebugConsole.ThrowError($"Cannot find a talent element from the children of the override element defined in {file.Path}"); } } else { TalentPrefabs.Add(new TalentPrefab(element, file.Path), false); } } break; default: DebugConsole.ThrowError($"Invalid XML root element: '{rootElement.Name.ToString()}' in {file.Path}"); break; } }
public ItemAssemblyPrefab(string filePath) { configPath = filePath; XDocument doc = XMLExtensions.TryLoadXml(filePath); if (doc == null || doc.Root == null) { return; } name = doc.Root.GetAttributeString("name", ""); identifier = doc.Root.GetAttributeString("identifier", null) ?? name.ToLowerInvariant().Replace(" ", ""); configElement = doc.Root; Category = MapEntityCategory.ItemAssembly; SerializableProperty.DeserializeProperties(this, configElement); int minX = int.MaxValue, minY = int.MaxValue; int maxX = int.MinValue, maxY = int.MinValue; DisplayEntities = new List <Pair <MapEntityPrefab, Rectangle> >(); foreach (XElement entityElement in doc.Root.Elements()) { string identifier = entityElement.GetAttributeString("identifier", ""); MapEntityPrefab mapEntity = List.Find(p => p.Identifier == identifier); if (mapEntity == null) { string entityName = entityElement.GetAttributeString("name", ""); mapEntity = List.Find(p => p.Name == entityName); } Rectangle rect = entityElement.GetAttributeRect("rect", Rectangle.Empty); if (mapEntity != null && !entityElement.GetAttributeBool("hideinassemblypreview", false)) { DisplayEntities.Add(new Pair <MapEntityPrefab, Rectangle>(mapEntity, rect)); minX = Math.Min(minX, rect.X); minY = Math.Min(minY, rect.Y - rect.Height); maxX = Math.Max(maxX, rect.Right); maxY = Math.Max(maxY, rect.Y); } } Bounds = new Rectangle(minX, minY, maxX - minX, maxY - minY); List.Add(this); }
public KarmaManager() { XDocument doc = XMLExtensions.TryLoadXml(ConfigFile); SerializableProperties = SerializableProperty.DeserializeProperties(this, doc?.Root); if (doc?.Root != null) { Presets["custom"] = doc.Root; foreach (XElement subElement in doc.Root.Elements()) { string presetName = subElement.GetAttributeString("name", ""); Presets[presetName.ToLowerInvariant()] = subElement; } SelectPreset("default"); } herpesAffliction = AfflictionPrefab.List.Find(ap => ap.Identifier == "spaceherpes"); }
private void AttachHuskAppendage(Character character) { //husk appendage already created, don't do anything if (huskAppendage != null) { return; } XDocument doc = XMLExtensions.TryLoadXml(Path.Combine("Content", "Characters", "Human", "huskappendage.xml")); if (doc == null || doc.Root == null) { return; } var limbElement = doc.Root.Element("limb"); if (limbElement == null) { DebugConsole.ThrowError("Error in huskappendage.xml - limb element not found"); return; } var jointElement = doc.Root.Element("joint"); if (jointElement == null) { DebugConsole.ThrowError("Error in huskappendage.xml - joint element not found"); return; } character.SetStun(0.5f); if (character.AnimController.Dir < 1.0f) { character.AnimController.Flip(); } var torso = character.AnimController.GetLimb(LimbType.Torso); huskAppendage = new Limb(character, limbElement); huskAppendage.body.Submarine = character.Submarine; huskAppendage.body.SetTransform(torso.SimPosition, torso.Rotation); character.AnimController.AddLimb(huskAppendage); character.AnimController.AddJoint(jointElement); }
public void LoadState(string filePath) { DebugConsole.Log($"Loading save file for an existing game session ({filePath})"); SaveUtil.DecompressToDirectory(filePath, SaveUtil.TempPath, null); string gamesessionDocPath = Path.Combine(SaveUtil.TempPath, "gamesession.xml"); XDocument doc = XMLExtensions.TryLoadXml(gamesessionDocPath); if (doc == null) { DebugConsole.ThrowError($"Failed to load the state of a multiplayer campaign. Could not open the file \"{gamesessionDocPath}\"."); return; } Load(doc.Root.Element("MultiPlayerCampaign")); GameMain.GameSession.OwnedSubmarines = SaveUtil.LoadOwnedSubmarines(doc, out SubmarineInfo selectedSub); GameMain.GameSession.SubmarineInfo = selectedSub; }
public ContentPackage(string filePath, string setPath = "") : this() { XDocument doc = XMLExtensions.TryLoadXml(filePath); Path = setPath == string.Empty ? filePath : setPath; if (doc?.Root == null) { DebugConsole.ThrowError("Couldn't load content package \"" + filePath + "\"!"); return; } Name = doc.Root.GetAttributeString("name", ""); HideInWorkshopMenu = doc.Root.GetAttributeBool("hideinworkshopmenu", false); CorePackage = doc.Root.GetAttributeBool("corepackage", false); SteamWorkshopUrl = doc.Root.GetAttributeString("steamworkshopurl", ""); GameVersion = new Version(doc.Root.GetAttributeString("gameversion", "0.0.0.0")); if (doc.Root.Attribute("installtime") != null) { InstallTime = ToolBox.Epoch.ToDateTime(doc.Root.GetAttributeUInt("installtime", 0)); } List <string> errorMsgs = new List <string>(); foreach (XElement subElement in doc.Root.Elements()) { if (!Enum.TryParse(subElement.Name.ToString(), true, out ContentType type)) { errorMsgs.Add("Error in content package \"" + Name + "\" - \"" + subElement.Name.ToString() + "\" is not a valid content type."); type = ContentType.None; } Files.Add(new ContentFile(subElement.GetAttributeString("file", ""), type)); } bool compatible = IsCompatible(); //If we know that the package is not compatible, don't display error messages. if (compatible) { foreach (string errorMsg in errorMsgs) { DebugConsole.ThrowError(errorMsg); } } }
public static void LoadPresets() { levelParams = new List <LevelGenerationParams>(); biomes = new List <Biome>(); var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.LevelGenerationParameters); if (!files.Any()) { files.Add("Content/Map/LevelGenerationParameters.xml"); } List <XElement> biomeElements = new List <XElement>(); List <XElement> levelParamElements = new List <XElement>(); foreach (string file in files) { XDocument doc = XMLExtensions.TryLoadXml(file); if (doc == null || doc.Root == null) { return; } foreach (XElement element in doc.Root.Elements()) { if (element.Name.ToString().ToLowerInvariant() == "biomes") { biomeElements.AddRange(element.Elements()); } else { levelParamElements.Add(element); } } } foreach (XElement biomeElement in biomeElements) { biomes.Add(new Biome(biomeElement)); } foreach (XElement levelParamElement in levelParamElements) { levelParams.Add(new LevelGenerationParams(levelParamElement)); } }
public void CheckForDuplicates(int index) { Dictionary <string, int> textCounts = new Dictionary <string, int>(); XDocument doc = XMLExtensions.TryLoadXml(filePath); if (doc == null || doc.Root == null) { return; } foreach (XElement subElement in doc.Root.Elements()) { string infoName = subElement.Name.ToString().ToLowerInvariant(); if (!textCounts.ContainsKey(infoName)) { textCounts.Add(infoName, 1); } else { textCounts[infoName] += 1; } } StringBuilder sb = new StringBuilder(); sb.Append("Language: " + Language); sb.AppendLine(); sb.Append("Duplicate entries:"); sb.AppendLine(); sb.AppendLine(); for (int i = 0; i < textCounts.Keys.Count; i++) { if (textCounts[texts.Keys.ElementAt(i)] > 1) { sb.Append(texts.Keys.ElementAt(i) + " Count: " + textCounts[texts.Keys.ElementAt(i)]); sb.AppendLine(); } } System.IO.StreamWriter file = new System.IO.StreamWriter(@"duplicate_" + Language.ToLower() + "_" + index + ".txt"); file.WriteLine(sb.ToString()); file.Close(); }
public static void Init() { var files = GameMain.Instance.GetFilesOfType(ContentType.Missions); foreach (string file in files) { XDocument doc = XMLExtensions.TryLoadXml(file); if (doc?.Root == null) { continue; } foreach (XElement element in doc.Root.Elements()) { List.Add(new MissionPrefab(element)); } } }
public CreditsPlayer(RectTransform rectT, string configFile) : base(null, rectT) { GameMain.Instance.ResolutionChanged += () => { ClearChildren(); Load(); }; var doc = XMLExtensions.TryLoadXml(configFile); if (doc == null) { return; } configElement = doc.Root; Load(); }
public static void LoadAll(IEnumerable <string> filePaths) { foreach (string filePath in filePaths) { XDocument doc = XMLExtensions.TryLoadXml(filePath); if (doc == null || doc.Root == null) { return; } foreach (XElement el in doc.Root.Elements()) { StructurePrefab sp = Load(el); List.Add(sp); } } }
public static void Init() { var files = GameMain.Instance.GetFilesOfType(ContentType.TraitorMissions); foreach (ContentFile file in files) { XDocument doc = XMLExtensions.TryLoadXml(file.Path); if (doc?.Root == null) { continue; } foreach (XElement element in doc.Root.Elements()) { List.Add(new TraitorMissionEntry(element)); } } }
public static bool LoadFromFile(string filePath, ContentPackage contentPackage, bool forceOverride = false) { XDocument doc = XMLExtensions.TryLoadXml(filePath); if (doc == null) { DebugConsole.ThrowError($"Loading character file failed: {filePath}"); return(false); } if (Prefabs.AllPrefabs.Any(kvp => kvp.Value.Any(cf => cf?.FilePath == filePath))) { DebugConsole.ThrowError($"Duplicate path: {filePath}"); return(false); } XElement mainElement = doc.Root.IsOverride() ? doc.Root.FirstElement() : doc.Root; var name = mainElement.GetAttributeString("name", null); if (name != null) { DebugConsole.NewMessage($"Error in {filePath}: 'name' is deprecated! Use 'speciesname' instead.", Color.Orange); } else { name = mainElement.GetAttributeString("speciesname", string.Empty); } if (string.IsNullOrWhiteSpace(name)) { DebugConsole.ThrowError($"No species name defined for: {filePath}"); return(false); } var identifier = name.ToLowerInvariant(); Prefabs.Add(new CharacterPrefab { Name = name, OriginalName = name, Identifier = identifier, FilePath = filePath, ContentPackage = contentPackage, XDocument = doc }, forceOverride || doc.Root.IsOverride()); return(true); }
public EnemyAIController(Character c, string file) : base(c) { targetMemories = new Dictionary <AITarget, AITargetMemory>(); XDocument doc = XMLExtensions.TryLoadXml(file); if (doc == null || doc.Root == null) { return; } XElement aiElement = doc.Root.Element("ai"); if (aiElement == null) { return; } attackRooms = aiElement.GetAttributeFloat(0.0f, "attackrooms", "attackpriorityrooms") / 100.0f; attackHumans = aiElement.GetAttributeFloat(0.0f, "attackhumans", "attackpriorityhumans") / 100.0f; attackWeaker = aiElement.GetAttributeFloat(0.0f, "attackweaker", "attackpriorityweaker") / 100.0f; attackStronger = aiElement.GetAttributeFloat(0.0f, "attackstronger", "attackprioritystronger") / 100.0f; eatDeadPriority = aiElement.GetAttributeFloat("eatpriority", 0.0f) / 100.0f; combatStrength = aiElement.GetAttributeFloat("combatstrength", 1.0f); attackCoolDown = aiElement.GetAttributeFloat("attackcooldown", 5.0f); sight = aiElement.GetAttributeFloat("sight", 0.0f); hearing = aiElement.GetAttributeFloat("hearing", 0.0f); attackWhenProvoked = aiElement.GetAttributeBool("attackwhenprovoked", false); fleeHealthThreshold = aiElement.GetAttributeFloat("fleehealththreshold", 0.0f); attachToWalls = aiElement.GetAttributeBool("attachtowalls", false); outsideSteering = new SteeringManager(this); insideSteering = new IndoorsSteeringManager(this, false); steeringManager = outsideSteering; state = AIState.None; }
private byte[] CalculateFileHash(ContentFile file) { var md5 = MD5.Create(); List <string> filePaths = new List <string> { file.Path }; List <byte> data = new List <byte>(); switch (file.Type) { case ContentType.Character: XDocument doc = XMLExtensions.TryLoadXml(file.Path); string speciesName = doc.Root.GetAttributeString("name", ""); //TODO: check non-default paths if defined filePaths.Add(RagdollParams.GetDefaultFile(speciesName, this)); foreach (AnimationType animationType in Enum.GetValues(typeof(AnimationType))) { filePaths.Add(AnimationParams.GetDefaultFile(speciesName, animationType, this)); } break; } foreach (string filePath in filePaths) { if (!File.Exists(filePath)) { continue; } using (var stream = File.OpenRead(filePath)) { byte[] fileData = new byte[stream.Length]; stream.Read(fileData, 0, (int)stream.Length); if (filePath.EndsWith(".xml", true, System.Globalization.CultureInfo.InvariantCulture)) { string text = System.Text.Encoding.UTF8.GetString(fileData); text = text.Replace("\n", "").Replace("\r", ""); fileData = System.Text.Encoding.UTF8.GetBytes(text); } data.AddRange(fileData); } } return(md5.ComputeHash(data.ToArray())); }
public static void Init() { var files = ContentPackage.GetFilesOfType(GameMain.Config.SelectedContentPackages, ContentType.MapGenerationParameters); if (!files.Any()) { DebugConsole.ThrowError("No map generation parameters found in the selected content packages!"); return; } // Let's not actually load the parameters until we have solved which file is the last, because loading the parameters takes some resources that would also need to be released. XElement selectedElement = null; foreach (string file in files) { XDocument doc = XMLExtensions.TryLoadXml(file); if (doc == null) { continue; } var mainElement = doc.Root; if (doc.Root.IsOverride()) { mainElement = doc.Root.FirstElement(); if (selectedElement != null) { DebugConsole.NewMessage($"Overriding the map generation parameters with '{file}'", Color.Yellow); } } else if (selectedElement != null) { DebugConsole.ThrowError($"Error in {file}: Another map generation parameter file already loaded! Use <override></override> tags to override it."); break; } selectedElement = mainElement; } if (selectedElement == null) { DebugConsole.ThrowError("Could not find a valid element in the map generation parameter files!"); } else { instance = new MapGenerationParams(selectedElement); } }
public static void Init() { List.Clear(); var files = GameMain.Instance.GetFilesOfType(ContentType.Missions); foreach (ContentFile file in files) { XDocument doc = XMLExtensions.TryLoadXml(file.Path); if (doc == null) { continue; } bool allowOverride = false; var mainElement = doc.Root; if (mainElement.IsOverride()) { allowOverride = true; mainElement = mainElement.FirstElement(); } foreach (XElement sourceElement in mainElement.Elements()) { var element = sourceElement.IsOverride() ? sourceElement.FirstElement() : sourceElement; var identifier = element.GetAttributeString("identifier", string.Empty); var duplicate = List.Find(m => m.Identifier == identifier); if (duplicate != null) { if (allowOverride || sourceElement.IsOverride()) { DebugConsole.NewMessage($"Overriding a mission with the identifier '{identifier}' using the file '{file.Path}'", Color.Yellow); List.Remove(duplicate); } else { DebugConsole.ThrowError($"Duplicate mission found with the identifier '{identifier}' in file '{file.Path}'! Add <override></override> tags as the parent of the mission definition to allow overriding."); // TODO: Don't allow adding duplicates when the issue with multiple missions is solved. //continue; } } List.Add(new MissionPrefab(element)); } } }
public static void LoadAll(IEnumerable <string> filePaths) { List = new Dictionary <string, JobPrefab>(); foreach (string filePath in filePaths) { XDocument doc = XMLExtensions.TryLoadXml(filePath); if (doc == null) { continue; } var mainElement = doc.Root.IsOverride() ? doc.Root.FirstElement() : doc.Root; if (doc.Root.IsOverride()) { DebugConsole.ThrowError($"Error in '{filePath}': Cannot override all job prefabs, because many of them are required by the main game! Please try overriding jobs one by one."); } foreach (XElement element in mainElement.Elements()) { if (element.IsOverride()) { var job = new JobPrefab(element.FirstElement()); if (List.TryGetValue(job.Identifier, out JobPrefab duplicate)) { DebugConsole.NewMessage($"Overriding the job '{duplicate.Identifier}' with another defined in '{filePath}'", Color.Yellow); List.Remove(duplicate.Identifier); } List.Add(job.Identifier, job); } else { if (List.TryGetValue(element.GetAttributeString("identifier", "").ToLowerInvariant(), out JobPrefab duplicate)) { DebugConsole.ThrowError($"Error in '{filePath}': Duplicate job definition found for: '{duplicate.Identifier}'. Use the <override> XML element as the parent of job element's definition to override the existing job."); } else { var job = new JobPrefab(element); List.Add(job.Identifier, job); } } } } }
public void StartServer() { XDocument doc = XMLExtensions.TryLoadXml(GameServer.SettingsFile); if (doc == null) { DebugConsole.ThrowError("File \"" + GameServer.SettingsFile + "\" not found. Starting the server with default settings."); Server = new GameServer("Server", 14242, false, "", false, 10); return; } Server = new GameServer( doc.Root.GetAttributeString("name", "Server"), doc.Root.GetAttributeInt("port", 14242), doc.Root.GetAttributeBool("public", false), doc.Root.GetAttributeString("password", ""), doc.Root.GetAttributeBool("enableupnp", false), doc.Root.GetAttributeInt("maxplayers", 10)); }
public static void LoadAll(IEnumerable <string> filePaths) { List = new List <JobPrefab>(); foreach (string filePath in filePaths) { XDocument doc = XMLExtensions.TryLoadXml(filePath); if (doc == null || doc.Root == null) { return; } foreach (XElement element in doc.Root.Elements()) { JobPrefab job = new JobPrefab(element); List.Add(job); } } }
public static void Init() { var locationTypeFiles = GameMain.Instance.GetFilesOfType(ContentType.LocationTypes); foreach (string file in locationTypeFiles) { XDocument doc = XMLExtensions.TryLoadXml(file); if (doc?.Root == null) { continue; } foreach (XElement element in doc.Root.Elements()) { LocationType locationType = new LocationType(element); List.Add(locationType); } } }
private void LoadDefaultConfig(bool setLanguage = true) { XDocument doc = XMLExtensions.TryLoadXml(savePath); if (doc == null) { GraphicsWidth = 1024; GraphicsHeight = 768; MasterServerUrl = ""; SelectContentPackage(ContentPackage.List.Any() ? ContentPackage.List[0] : new ContentPackage("")); jobPreferences = new List <string>(); foreach (string job in JobPrefab.List.Keys) { jobPreferences.Add(job); } return; } bool resetLanguage = setLanguage || string.IsNullOrEmpty(Language); SetDefaultValues(resetLanguage); SetDefaultBindings(doc, legacy: false); MasterServerUrl = doc.Root.GetAttributeString("masterserverurl", MasterServerUrl); RemoteContentUrl = doc.Root.GetAttributeString("remotecontenturl", RemoteContentUrl); WasGameUpdated = doc.Root.GetAttributeBool("wasgameupdated", WasGameUpdated); VerboseLogging = doc.Root.GetAttributeBool("verboselogging", VerboseLogging); SaveDebugConsoleLogs = doc.Root.GetAttributeBool("savedebugconsolelogs", SaveDebugConsoleLogs); AutoUpdateWorkshopItems = doc.Root.GetAttributeBool("autoupdateworkshopitems", AutoUpdateWorkshopItems); LoadGeneralSettings(doc, resetLanguage); LoadGraphicSettings(doc); LoadAudioSettings(doc); LoadControls(doc); LoadContentPackages(doc); #if DEBUG WindowMode = WindowMode.Windowed; #endif UnsavedSettings = false; }
public void Load(string filePath) { XDocument doc = XMLExtensions.TryLoadXml(filePath); if (doc == null) { DebugConsole.ThrowError("No config file found"); MasterServerUrl = ""; SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage(""); return; } MasterServerUrl = doc.Root.GetAttributeString("masterserverurl", ""); AutoCheckUpdates = doc.Root.GetAttributeBool("autocheckupdates", true); WasGameUpdated = doc.Root.GetAttributeBool("wasgameupdated", false); VerboseLogging = doc.Root.GetAttributeBool("verboselogging", false); InitProjSpecific(doc); foreach (XElement subElement in doc.Root.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "contentpackage": string path = subElement.GetAttributeString("path", ""); SelectedContentPackage = ContentPackage.list.Find(cp => cp.Path == path); if (SelectedContentPackage == null) { SelectedContentPackage = new ContentPackage(path); } break; } } }
private void LoadConfig(string configPath) { try { XDocument doc = XMLExtensions.TryLoadXml(configPath); if (doc == null || doc.Root == null) { return; } foreach (XElement element in doc.Root.Elements()) { prefabs.Add(new BackgroundSpritePrefab(element)); } } catch (Exception e) { DebugConsole.ThrowError(String.Format("Failed to load BackgroundSprites from {0}", configPath), e); } }
private byte[] CalculateXmlHash(ContentFile file, ref MD5 md5) //todo: Change ref to in (in C# 7.2) { var doc = XMLExtensions.TryLoadXml(file.path); if (doc == null) { throw new Exception($"file {file.path} could not be opened as XML document"); } using (var memoryStream = new MemoryStream()) { using (var writer = new StreamWriter(memoryStream)) { writer.Write(doc.ToString()); writer.Flush(); memoryStream.Position = 0; return(md5.ComputeHash(memoryStream)); } } }
public static void LoadFromFile(ContentFile file) { XDocument doc = XMLExtensions.TryLoadXml(file.Path); if (doc == null) { return; } var mainElement = doc.Root.IsOverride() ? doc.Root.FirstElement() : doc.Root; if (doc.Root.IsOverride()) { DebugConsole.ThrowError($"Error in '{file.Path}': Cannot override all job prefabs, because many of them are required by the main game! Please try overriding jobs one by one."); } foreach (XElement element in mainElement.Elements()) { if (element.Name.ToString().Equals("nojob", StringComparison.OrdinalIgnoreCase)) { continue; } if (element.IsOverride()) { var job = new JobPrefab(element.FirstElement(), file.Path) { ContentPackage = file.ContentPackage }; Prefabs.Add(job, true); } else { var job = new JobPrefab(element, file.Path) { ContentPackage = file.ContentPackage }; Prefabs.Add(job, false); } } NoJobElement = NoJobElement ?? mainElement.Element("NoJob"); NoJobElement = NoJobElement ?? mainElement.Element("nojob"); }
static Order() { PrefabList = new List <Order>(); XDocument doc = XMLExtensions.TryLoadXml(ConfigFile); if (doc == null || doc.Root == null) { return; } foreach (XElement orderElement in doc.Root.Elements()) { if (orderElement.Name.ToString().ToLowerInvariant() != "order") { continue; } var newOrder = new Order(orderElement); newOrder.Prefab = newOrder; PrefabList.Add(newOrder); } }