Skip to content

Instantly share code, notes, and snippets.

@billw2012
Last active March 4, 2023 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billw2012/83544a40ca98bdae47c3d767e1dbc525 to your computer and use it in GitHub Desktop.
Save billw2012/83544a40ca98bdae47c3d767e1dbc525 to your computer and use it in GitHub Desktop.
Powershell script that generates a mod to scale X4 module build time
$diff = New-Object System.Xml.XmlDocument
$diff.AppendChild($diff.CreateXmlDeclaration("1.0", "UTF-8", $null))
$diffRoot = $diff.CreateElement("diff")
$diff.AppendChild($diffRoot)
$inputFiles = Get-ChildItem -Path "C:\Temp\X4" -Filter "wares.xml" -Recurse
foreach ($file in $inputFiles) {
[xml]$xml = Get-Content $file.FullName
foreach ($node in $xml.SelectNodes("//ware[@id]")) {
if ($node.id.StartsWith("module_")) {
foreach ($production in $node.production) {
$sel = "/wares/ware[@id='$($node.id)']/production[@method='$($production.method)']/@time"
$content = 10 + [int]($production.time / 10)
$replace = $diff.CreateElement("replace")
$replace.SetAttribute("sel", $sel)
$replace.InnerText = $content.ToString()
$diffRoot.AppendChild($replace)
}
}
}
}
$diff.Save("C:\temp\diff.xml")
@billw2012
Copy link
Author

Extract all X4 content (including dlcs) to C:\Temp\X4 and then run it to generate the new patch xml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment