Advertisement
Zaphodikus

Empyrion Galactic Survival Blueprint BA/CV toggle

Dec 29th, 2016
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. # http://softcircuitry.blogspot.co.uk/2016/12/empyrion-galactic-survival-blueprint.html
  2. # If you see an error:
  3. # .\Toggle-Blueprint.ps1 : File Toggle-Blueprint.ps1 cannot be loaded. The
  4. # file Toggle-Blueprint.ps1 is not digitally signed. You cannot run this
  5. # script on the current system. For more information about running scripts and setting execution policy, see
  6. # about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
  7. # Then open powershell using RunAs Administrator, and type in
  8. # PS:\> set-executionpolicy Bypass
  9. #
  10. # Converts a CV to a BA blueprint or back (or HV to a SV)
  11. # Optionally provide the name of a blueprint (without the file extension)
  12. # Will not overwrite an existing BP
  13. # Help:
  14. [cmdletbinding()]
  15. Param($inputFile="", $outputFile="", [switch]$flatten)
  16. Set-strictmode -version 2
  17. $erroractionpreference = 'stop'
  18.  
  19. $basePath = @(ls 'C:\Program Files (x86)\Steam\steamapps\common\Empyrion - Galactic Survival\Saves\Blueprints' -recurse -include 'Workshop.data')[0] | split-path -parent
  20. if ([string]::Isnullorempty($inputFile)) {
  21. $list = ls $basePath -exclude 'workshop.data'
  22. [int]$i=0
  23. foreach ($file in $list) {
  24. $fname = join-path $file.fullname ($file.name + '.epb')
  25. write-host "$i $($file.name) [$((get-item $fname).length)]" -foregroundcolor cyan
  26. $i+=1
  27. }
  28. $inputfile = $list[ (Read-host "choice?") ].name
  29. }
  30. if ([string]::Isnullorempty($outputFile)) {
  31. $outputFile = $inputfile +'(1)'
  32. }
  33. Write-host "Loading: $inputfile"
  34.  
  35. $fname = join-path (join-path $basepath $inputfile) ($inputfile + '.epb')
  36. $bytes = [System.IO.File]::ReadAllBytes($fname)
  37. # read some basic stats
  38. $newClass = 0
  39. $entityClass = switch ($bytes[8]) { # (0x02 = BA, 0x04 = SV, 0x08 = CV, 0x10 = HV)
  40. 16 {$msg = 'HV to SV?'; 'HV'; $newClass=4}
  41. 4 {$msg = 'SV to HV?'; 'SV'; $newClass=16}
  42. 8 {$msg = 'CV to BA?'; 'CV'; $newClass=2}
  43. 2 {$msg = 'BA to CV?'; 'BA'; $newClass=8}
  44. default {'unknown'}
  45. }
  46. $entityWidth = [bitconverter]::ToInt16( $Bytes,9)
  47. $entityHeight = [bitconverter]::ToInt16( $Bytes,13)
  48. $entityDepth = [bitconverter]::ToInt16( $Bytes,17)
  49. $terrainFlag = $bytes[33];
  50. 0..40 | %{write-verbose "$_ $($bytes[$_])"}
  51. write-host "type [Width, Height, Depth] Flatten"
  52. write-host "$entityclass [ $entityWidth, $entityHeight, $entityDepth] $terrainFlag"
  53. if (($flatten) -and ($entityClass -eq 'BA')) {
  54. # todo make it a toggle
  55. $msg = "Flatten Terrain? ($terrainFlag)"
  56. write-warning "The flatten terrain option does not always work, test it a few times before sharing the results"
  57. } else {
  58. $msg = "Convert " + $msg
  59. }
  60. $ans = Read-Host $msg
  61. if (('Y' -eq $ans.ToUpper()) -and (($newClass) -or ($flatten))) {
  62. if ('Y' -eq (Read-Host "Are you sure?").ToUpper()) {
  63. if (($flatten) -and ($entityClass -eq 'BA')) {
  64. # todo make it a toggle
  65. $bytes[4] = 1
  66. $bytes[33] = 1
  67. } else {
  68. $bytes[8] = $newClass
  69. }
  70. $newProjectName = $outputFile
  71. mkdir (join-path $basePath $newProjectName) | out-null
  72. $newProjectPath = join-path (join-path $basePath $newProjectName) ($newProjectName + '.epb')
  73. write-host "Saving $newProjectPath ..."
  74. [io.file]::WriteAllBytes($newProjectPath, $bytes)
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement