Skip to content

Instantly share code, notes, and snippets.

@vexx32
Last active April 6, 2021 03:47
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 vexx32/9c51583291b5cf176d97bd8bb2b85ae0 to your computer and use it in GitHub Desktop.
Save vexx32/9c51583291b5cf176d97bd8bb2b85ae0 to your computer and use it in GitHub Desktop.
# Navigate to "C:\Users\<USERNAME>\AppData\LocalLow\Nolla_Games_Noita" before running this script.
# You must have already run the unpacker in the Noita application directory to have access to the files.
[xml]$xml = Get-Content ./data/materials.xml
$materials = $xml.Materials.CellData
$childMaterials = $xml.Materials.CellDataChild
$script:NameLookup = @{}
$translations = @(
Import-Csv -Path 'C:\Program Files (x86)\Steam\steamapps\common\Noita\data\translations\common.csv' -WarningAction Ignore
Import-Csv -Path 'C:\Program Files (x86)\Steam\steamapps\common\Noita\data\translations\common_dev.csv' -WarningAction Ignore
) | Where-Object H1 -like mat_* |
ForEach-Object {
$script:NameLookup[$_.H1] = [cultureinfo]::CurrentCulture.TextInfo.ToTitleCase($_.en)
}
$materialLookup = @{}
foreach ($mat in $materials + $childMaterials) {
$materialLookup[$mat.name] = $mat
}
function Get-LocalisedName {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]
$InternalName,
[Parameter()]
[string]
$Delimiter = ' '
)
$material = $materialLookup[$InternalName]
$nameKey = $material.ui_name -replace '^\$'
if (-not $nameKey -and $material._parent) {
$nameKey = $materialLookup[$material._parent].ui_name
}
$value = if ($script:NameLookup.ContainsKey($nameKey)) {
'{0}{2}({1})' -f $script:NameLookup[$nameKey], $InternalName, $Delimiter
}
else {
$InternalName
}
$value
}
# name, _parent, _inherit_reactions, density, durability, tags, type[solid/liquid]
$materialFinalList = @(
$materials | Select-Object -Property @(
@{
name = 'Name'
expression = {
$key = $_.ui_name -replace '^\$'
$script:NameLookup[$key]
}
}
@{ name = 'InternalName'; expression = 'Name' }
@{ name = 'Parent'; expression = { $null } }
@{ name = 'InheritsReactions'; expression = { $null } }
'Density'
'Durability'
'HP'
'Tags'
@{ name = 'Type'; expression = { $_.cell_type } }
)
$childMaterials | Select-Object -Property @(
@{
name = 'Name'
expression = {
$key = $_.ui_name -replace '^\$'
$name = if (-not $key) {
$key = $materialLookup[$_._parent].ui_name -replace '^\$'
$script:NameLookup[$key]
}
else {
$script:NameLookup[$key]
}
$name
}
}
@{ name = 'InternalName'; expression = 'Name' }
@{ name = 'Parent'; expression = '_parent' }
@{
name = 'InheritsReactions'
expression = { $_._inherit_reactions -as [int] -as [bool] }
}
@{
name = 'Density'
expression = {
if ($_.density) {
$_.density
}
else {
$materialLookup[$_._parent].density
}
}
}
@{
name = 'Durability'
expression = {
if ($_.durability) {
$_.durability
}
else {
$materialLookup[$_._parent].durability
}
}
}
@{
name = 'HP'
expression = {
if ($_.hp) {
$_.hp
}
else {
$materialLookup[$_._parent].hp
}
}
}
@{
name = 'Tags'
expression = {
$(
@(
if ($_.tags) { $_.tags -split ',' }
$materialLookup[$_._parent].tags -split ','
) | Select-Object -Unique
) -join ','
}
}
@{
name = 'Type'
expression = {
if ($_.cell_type) {
$_.cell_type
}
else {
$materialLookup[$_._parent].cell_type
}
}
}
)
)
$materialFinalList | Export-Csv -Path ./materials_info.csv
$reactions = $xml.Materials.Reaction | Select-Object -Property @(
'Probability'
@{ name = 'Reactant1'; expression = { Get-LocalisedName -InternalName $_.input_cell1 -Delimiter "`n" } }
@{ name = 'Reactant2'; expression = { Get-LocalisedName -InternalName $_.input_cell2 -Delimiter "`n" } }
@{ name = 'Reactant3'; expression = { Get-LocalisedName -InternalName $_.input_cell3 -Delimiter "`n" } }
@{ name = 'Product1'; expression = { Get-LocalisedName -InternalName $_.output_cell1 -Delimiter "`n" } }
@{ name = 'Product2'; expression = { Get-LocalisedName -InternalName $_.output_cell2 -Delimiter "`n" } }
@{ name = 'Product3'; expression = { Get-LocalisedName -InternalName $_.output_cell3 -Delimiter "`n" } }
)
$reactions | Export-Csv -Path ./materials_reactions.csv
[System.Collections.Generic.HashSet[string]]$tagList = $materialFinalList |
ForEach-Object { $_.Tags -split ',' } |
Where-Object { $_ }
$materialTags = @{}
foreach ($tag in $tagList) {
$materialTags[$tag] = $materialFinalList.Where{ $_.Tags -and $_.Tags.Contains($tag) }.InternalName | Sort-Object
}
$maxCount = $materialTags.Keys.ForEach{$materialTags[$_].Count} |
Measure-Object -Maximum |
Select-Object -ExpandProperty Maximum
$orderedTags = $tagList -as [System.Collections.Generic.SortedSet[string]]
$tagResults = for ($i = 0; $i -lt $maxCount; $i++) {
$object = [ordered]@{}
foreach ($key in $orderedTags) {
$material = @($materialTags[$key])[$i]
if ($material) {
$object.$key = Get-LocalisedName -InternalName $material -Delimiter "`n"
}
}
[PSCustomObject]$object
}
$tagResults | Export-Csv -Path ./materials_tags.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment