Add-Type -AssemblyName System.Windows.Forms # --- Function: Select the Space Engineers "Data" folder --- function Select-SEDataFolder { $dialog = New-Object System.Windows.Forms.FolderBrowserDialog $dialog.Description = "Select the Space Engineers 'Data' folder (contains CubeBlocks.sbc)" $dialog.ShowNewFolderButton = $false if ($dialog.ShowDialog() -eq "OK") { return $dialog.SelectedPath } else { Write-Host "No folder selected. Exiting." -ForegroundColor Yellow exit } } # --- Function: Ask user where to save the .log file --- function Select-LogFile { $dialog = New-Object System.Windows.Forms.SaveFileDialog $dialog.Title = "Save Block Index Log File" $dialog.Filter = "Log File (*.log)|*.log" $dialog.FileName = "BlockIndex.log" if ($dialog.ShowDialog() -eq "OK") { return $dialog.FileName } else { Write-Host "No save location selected. Exiting." -ForegroundColor Yellow exit } } # --- Function: Write to both console and log file --- function Write-Log { param( [string]$Text, [string]$Color = "White" ) Write-Host $Text -ForegroundColor $Color Add-Content -Path $Global:LogFile -Value $Text } # --- Function: Extract block definitions from SBC files --- function Parse-BlockDefinitions { param([string]$FilePath) Write-Log " Loading definitions from: $FilePath" "Cyan" try { [xml]$xml = Get-Content $FilePath -ErrorAction Stop } catch { Write-Log "Failed to read SBC file." "Red" return $null } return $xml.Definitions.CubeBlocks.ChildNodes } # --- MAIN SCRIPT --- Write-Host " Space Engineers Block Index Generator " -ForegroundColor Magenta $folder = Select-SEDataFolder Write-Host " Selected Folder: $folder" -ForegroundColor Yellow # Ask user where to save the log file $Global:LogFile = Select-LogFile Write-Host " Log file will be saved to: $LogFile" -ForegroundColor Green "" | Out-File $LogFile # Clear/create file # Find CubeBlocks.sbc and modded block definition files $sbcFiles = Get-ChildItem -Path $folder -Filter *CubeBlocks*.sbc -Recurse if ($sbcFiles.Count -eq 0) { Write-Log "No CubeBlocks SBC files found." "Red" exit } Write-Log " Found $($sbcFiles.Count) definition file(s). Parsing..." "Green" $BlockIndex = @{} foreach ($file in $sbcFiles) { $blocks = Parse-BlockDefinitions -FilePath $file.FullName if ($blocks -eq $null) { continue } foreach ($block in $blocks) { $name = $block.Id.SubtypeId if (-not $name) { continue } if (-not $BlockIndex.ContainsKey($name)) { $BlockIndex[$name] = [ordered]@{ LargeGrid = @() SmallGrid = @() } } $gridSize = $block.CubeSize if (-not $gridSize) { $gridSize = "Large" } $components = @() foreach ($comp in $block.Components.Component) { $components += "$($comp.Subtype) x$($comp.Count)" } if ($gridSize -eq "Large") { $BlockIndex[$name].LargeGrid = $components } else { $BlockIndex[$name].SmallGrid = $components } } } Write-Log " COMPLETE BLOCK INDEX " "Red" foreach ($entry in $BlockIndex.GetEnumerator() | Sort-Object Name) { Write-Log " Block: $($entry.Key)" "Cyan" Write-Log " Large Grid Components:" "Green" if ($entry.Value.LargeGrid.Count -gt 0) { $entry.Value.LargeGrid | ForEach-Object { Write-Log " $_" } } else { Write-Log " None" } Write-Log " Small Grid Components:" "Yellow" if ($entry.Value.SmallGrid.Count -gt 0) { $entry.Value.SmallGrid | ForEach-Object { Write-Log " $_" } } else { Write-Log " None" } } Write-Log " INDEX GENERATION COMPLETE " "Magenta" Write-Host " Log saved to: $LogFile" -ForegroundColor Cyan