Last active
March 4, 2023 18:26
-
-
Save billw2012/83544a40ca98bdae47c3d767e1dbc525 to your computer and use it in GitHub Desktop.
Powershell script that generates a mod to scale X4 module build time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extract all X4 content (including dlcs) to C:\Temp\X4 and then run it to generate the new patch xml.