/// <summary> /// Loads the mod descriptor (content.xml) from an IMod. /// </summary> /// <param name="p_modMod">The mod to be activated</param> /// <returns>Null on error otherwise the mod name</returns> private string LoadModNameInternal(IMod p_modMod) { var bteContentFile = p_modMod.GetFile("content.xml"); var strContentXml = Encoding.UTF8.GetString(bteContentFile); var xdocContentXml = XDocument.Parse(strContentXml); if (xdocContentXml.Root != null) { return(xdocContentXml.Root.Attribute("name").Value); } return(null); }
private void AddManifest(IMod p_modMod) { string strAddins = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Bioware\Dragon Age\Settings\AddIns.xml"); XDocument XDoc = XDocument.Load(strAddins); XDocument docManifest = XDocument.Parse(Encoding.ASCII.GetString(p_modMod.GetFile("Manifest.xml"))); XElement xelAddinsList = docManifest.Descendants("AddInsList").FirstOrDefault(); foreach (XElement XAddin in xelAddinsList.Elements("AddInItem")) { XDoc.Root.Add(XAddin); } XDoc.Save(strAddins); }
private void RemoveManifest(IMod p_modMod) { string profilesDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Larian Studios\Baldur's Gate 3\PlayerProfiles"); if (Directory.Exists(profilesDirectory)) { DirectoryInfo diProfiles = new DirectoryInfo(profilesDirectory); foreach (DirectoryInfo dir in diProfiles.GetDirectories()) { if (!dir.Name.Equals("default", StringComparison.OrdinalIgnoreCase)) { string manifest = Path.Combine(dir.FullName, "modsettings.lsx"); if (File.Exists(manifest)) { XmlDocument XDoc = new XmlDocument(); XDoc.Load(manifest); XmlNode xmlMods = XDoc.DocumentElement.SelectSingleNode("//*[@id='Mods']"); XmlNode xmlChildren = xmlMods.FirstChild; BG3Json currentMod = LoadJson(Encoding.ASCII.GetString(p_modMod.GetFile("info.json"))); foreach (BG3Mod mod in currentMod.Mods) { XmlNode xmlMod = XDoc.DocumentElement.SelectSingleNode("//*[@value='" + mod.UUID + "']"); if (xmlMod != null) { XmlNode parent = xmlMod.ParentNode; xmlChildren.RemoveChild(parent); } } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; using (XmlWriter writer = XmlWriter.Create(manifest, settings)) { XDoc.Save(writer); } } } } } }
/// <summary> /// Loads the mod descriptor (content.xml) from an IMod. /// </summary> /// <param name="p_modMod">The mod to be activated</param> /// <returns>Null on error otherwise the mod name</returns> private string LoadModNameInternal(IMod p_modMod) { var bteContentFile = p_modMod.GetFile("content.xml"); var strContentXml = Encoding.UTF8.GetString(bteContentFile); var xdocContentXml = XDocument.Parse(strContentXml); if (xdocContentXml.Root != null) { return xdocContentXml.Root.Attribute("name").Value; } return null; }
/// <summary> /// Merges the chargenmorphcfg.xml file of the Dragon Age mods. /// </summary> /// <param name="p_rolActiveMods">The list of active mods.</param> /// <param name="p_modMod">The current mod.</param> /// <param name="p_booRemove">Whether we're adding or removing the mod.</param> public override void ModFileMerge(ReadOnlyObservableList <IMod> p_rolActiveMods, IMod p_modMod, bool p_booRemove) { List <string> lstFiles = null; XDocument XDoc = null; XDocument XDocMerge = null; bool booMerge = false; Byte[] bFile = null; strXMLDirectory = Path.Combine(m_gmdGameModeInfo.InstallationPath, "NMM_chargenmorphcfg"); #region activeMods if (p_booRemove && File.Exists(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml"))) { File.Delete(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml")); } if ((!File.Exists(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml"))) || (p_booRemove)) { foreach (IMod modMod in p_rolActiveMods) { if (modMod.Filename != p_modMod.Filename) { lstFiles = modMod.GetFileList(); foreach (string strFile in lstFiles) { if (strFile.EndsWith("chargenmorphcfg.xml")) { bFile = modMod.GetFile(strFile); string responseText = Encoding.ASCII.GetString(bFile); XDoc = XDocument.Parse(responseText.Replace("???", "")); if (XDocMerge == null) { XDocMerge = XDoc; booMerge = true; } else { foreach (XElement ele in XDoc.Root.Elements()) { XElement xeDoc = XDoc.Root.Element(ele.Name.ToString()); XElement xeDocMerge = XDocMerge.Root.Element(ele.Name.ToString()); MergeElements(xeDoc, xeDocMerge); } } } } } } } else { bFile = File.ReadAllBytes(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml")); string responseText = Encoding.ASCII.GetString(bFile); XDoc = XDocument.Parse(responseText.Replace("???", "")); booMerge = true; } #endregion #region currentMod if ((p_modMod != null) && (!p_rolActiveMods.Contains(p_modMod))) { lstFiles = p_modMod.GetFileList(); foreach (string strFile in lstFiles) { if (strFile.EndsWith("chargenmorphcfg.xml")) { bFile = p_modMod.GetFile(strFile); string responseText = Encoding.ASCII.GetString(bFile); XDocMerge = XDocument.Parse(responseText.Replace("???", "")); if (booMerge) { foreach (XElement ele in XDoc.Root.Elements()) { XElement xeDoc = XDoc.Root.Element(ele.Name.ToString()); XElement xeDocMerge = XDocMerge.Root.Element(ele.Name.ToString()); MergeElements(xeDoc, xeDocMerge); } } } } } #endregion if (!Directory.Exists(strXMLDirectory)) { Directory.CreateDirectory(strXMLDirectory); } if (XDoc != null) { XDoc.Save(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml")); } else if (XDocMerge != null) { XDocMerge.Save(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml")); } }
/// <summary> /// Merges the chargenmorphcfg.xml file of the Dragon Age mods. /// </summary> /// <param name="p_rolActiveMods">The list of active mods.</param> /// <param name="p_modMod">The current mod.</param> /// <param name="p_booRemove">Whether we're adding or removing the mod.</param> public override void ModFileMerge(ReadOnlyObservableList<IMod> p_rolActiveMods, IMod p_modMod, bool p_booRemove) { List<string> lstFiles = null; XDocument XDoc = null; XDocument XDocMerge = null; bool booMerge = false; Byte[] bFile = null; strXMLDirectory = Path.Combine(m_gmdGameModeInfo.InstallationPath, "NMM_chargenmorphcfg"); #region activeMods if (p_booRemove && File.Exists(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml"))) File.Delete(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml")); if ((!File.Exists(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml"))) || (p_booRemove)) { foreach (IMod modMod in p_rolActiveMods) { if (modMod.Filename != p_modMod.Filename) { lstFiles = modMod.GetFileList(); foreach (string strFile in lstFiles) { if (strFile.EndsWith("chargenmorphcfg.xml")) { bFile = modMod.GetFile(strFile); string responseText = Encoding.ASCII.GetString(bFile); XDoc = XDocument.Parse(responseText.Replace("???", "")); if (XDocMerge == null) { XDocMerge = XDoc; booMerge = true; } else { foreach (XElement ele in XDoc.Root.Elements()) { XElement xeDoc = XDoc.Root.Element(ele.Name.ToString()); XElement xeDocMerge = XDocMerge.Root.Element(ele.Name.ToString()); MergeElements(xeDoc, xeDocMerge); } } } } } } } else { bFile = File.ReadAllBytes(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml")); string responseText = Encoding.ASCII.GetString(bFile); XDoc = XDocument.Parse(responseText.Replace("???", "")); booMerge = true; } #endregion #region currentMod if ((p_modMod != null) && (!p_rolActiveMods.Contains(p_modMod))) { lstFiles = p_modMod.GetFileList(); foreach (string strFile in lstFiles) { if (strFile.EndsWith("chargenmorphcfg.xml")) { bFile = p_modMod.GetFile(strFile); string responseText = Encoding.ASCII.GetString(bFile); XDocMerge = XDocument.Parse(responseText.Replace("???", "")); if (booMerge) { foreach (XElement ele in XDoc.Root.Elements()) { XElement xeDoc = XDoc.Root.Element(ele.Name.ToString()); XElement xeDocMerge = XDocMerge.Root.Element(ele.Name.ToString()); MergeElements(xeDoc, xeDocMerge); } } } } } #endregion if (!Directory.Exists(strXMLDirectory)) Directory.CreateDirectory(strXMLDirectory); if(XDoc != null) XDoc.Save(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml")); else if(XDocMerge != null) XDocMerge.Save(Path.Combine(strXMLDirectory, "chargenmorphcfg.xml")); }
private void AddManifest(IMod p_modMod) { string strAddins = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Bioware\Dragon Age\Settings\AddIns.xml"); XDocument XDoc = XDocument.Load(strAddins); XDocument docManifest = XDocument.Parse(Encoding.ASCII.GetString(p_modMod.GetFile("Manifest.xml"))); XElement xelAddinsList = docManifest.Descendants("AddInsList").FirstOrDefault(); foreach (XElement XAddin in xelAddinsList.Elements("AddInItem")) XDoc.Root.Add(XAddin); XDoc.Save(strAddins); }
private void AddManifest(IMod p_modMod) { string profilesDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Larian Studios\Baldur's Gate 3\PlayerProfiles"); if (Directory.Exists(profilesDirectory)) { DirectoryInfo diProfiles = new DirectoryInfo(profilesDirectory); foreach (DirectoryInfo dir in diProfiles.GetDirectories()) { if (!dir.Name.Equals("default", StringComparison.OrdinalIgnoreCase)) { string manifest = Path.Combine(dir.FullName, "modsettings.lsx"); if (File.Exists(manifest)) { XmlDocument XDoc = new XmlDocument(); XDoc.Load(manifest); XmlNode xmlMods = XDoc.DocumentElement.SelectSingleNode("//*[@id='Mods']"); XmlNode xmlChildren = xmlMods.FirstChild; BG3Json currentMod = LoadJson(Encoding.ASCII.GetString(p_modMod.GetFile("info.json"))); foreach (BG3Mod mod in currentMod.Mods) { XmlNode xmlCheck = XDoc.DocumentElement.SelectSingleNode("//*[@value='" + mod.UUID + "']"); if (xmlCheck == null) { XmlElement modDesc = XDoc.CreateElement("node"); modDesc.SetAttribute("id", "ModuleShortDesc"); XmlElement attribute = XDoc.CreateElement("attribute"); attribute.SetAttribute("id", "Folder"); attribute.SetAttribute("type", "LSString"); attribute.SetAttribute("value", mod.Folder); modDesc.AppendChild(attribute); attribute = XDoc.CreateElement("attribute"); attribute.SetAttribute("id", "MD5"); attribute.SetAttribute("type", "LSString"); attribute.SetAttribute("value", string.Empty); modDesc.AppendChild(attribute); attribute = XDoc.CreateElement("attribute"); attribute.SetAttribute("id", "Name"); attribute.SetAttribute("type", "LSString"); attribute.SetAttribute("value", mod.Name); modDesc.AppendChild(attribute); attribute = XDoc.CreateElement("attribute"); attribute.SetAttribute("id", "UUID"); attribute.SetAttribute("type", "FixedString"); attribute.SetAttribute("value", mod.UUID); modDesc.AppendChild(attribute); attribute = XDoc.CreateElement("attribute"); attribute.SetAttribute("id", "Version64"); attribute.SetAttribute("type", "int64"); attribute.SetAttribute("value", mod.Version ?? "1"); modDesc.AppendChild(attribute); xmlChildren.AppendChild(modDesc); } } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; using (XmlWriter writer = XmlWriter.Create(manifest, settings)) { XDoc.Save(writer); } } } } } }