VasVadum

Make GPL - Majesty HD Modding Script

Sep 19th, 2021 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Script by EVWeb, edited by Anoyomouse & Vas
  2. # Script checks if the SDK path is set. If not, asks where, and then sets it on the User level.
  3. # After that, the script reads the project files to figure out how to process the mod data.
  4.  
  5. # Set working dir to current script dir
  6. $path = Split-Path $MyInvocation.MyCommand.Path -Parent
  7.  
  8. Clear-Host
  9.  
  10. Write-Host "Running compiler for mod: $($path)`n"
  11.  
  12. # Make sure SDK is installed
  13. if([string]::IsNullOrWhiteSpace($env:MAJESTYSDK) -or
  14.     -not (Test-Path $env:MAJESTYSDK) -or
  15.     -not (Test-Path "$env:MAJESTYSDK\gplbcc.exe"))
  16. {
  17.     Add-Type -AssemblyName System.Windows.Forms
  18.    
  19.     $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{
  20.         ShowNewFolderButton = $false
  21.         Description = 'The Majesty SDK Folder has not been set, please locate it.'
  22.     }
  23.    
  24.     $result = $FolderBrowser.ShowDialog()
  25.    
  26.     # See if SDK path was set
  27.     if($result -ne [System.Windows.Forms.DialogResult]::OK)
  28.     {
  29.         Write-Host "ERROR: Unable to find the GPL compiler.  Set the MAJESTYSDK environment variable to point to the SDK path." -ForegroundColor Red
  30.         exit 1;
  31.     }
  32.    
  33.     $env:MAJESTYSDK = $FolderBrowser.SelectedPath
  34.     # Persist the environment variable
  35.     [System.Environment]::SetEnvironmentVariable("MAJESTYSDK", $env:MAJESTYSDK, 'User')
  36. }
  37.  
  38. $sdk = $env:MAJESTYSDK + "\gplbcc.exe"
  39. If (-not (Test-Path $sdk)) {
  40.     Write-Error "Could not find the gplbcc compiler at ($sdk)";
  41.     Exit(1)
  42. }
  43.  
  44. #Read Main Project and create the GPLProjs
  45. $mmxmls = Get-ChildItem -Include *.mmxml -Name
  46.  
  47. foreach($mmxml in $mmxmls)
  48. {
  49.     [xml]$xml = Get-Content $mmxml
  50.    
  51.     foreach($mod in $xml.Majesty.Mod)
  52.     {
  53.         foreach($gpl in $mod.DataConfiguration.Dataset.Load.GPL)
  54.         {
  55.             $target = $gpl.Target
  56.             if(Test-Path $target)
  57.             {
  58.                 Write-Host "Removing old $($target)" -ForegroundColor DarkYellow
  59.                 Remove-Item $target
  60.             }
  61.            
  62.             $gplproj = [System.IO.Path]::GetFileNameWithoutExtension($target) + ".gplproj"
  63.             if(Test-Path $gplproj)
  64.             {
  65.                 Write-Host "Removing old $($gplproj)" -ForegroundColor DarkYellow
  66.                 Remove-Item $gplproj
  67.             }
  68.            
  69.             $projContent = "";
  70.             foreach($source in $gpl.Source)
  71.             {
  72.                 if( $source.EndsWith(".dat") )
  73.                 {
  74.                     $projContent += 'data="'
  75.                 }
  76.                 else
  77.                 {
  78.                     $projContent += 'source="'
  79.                 }
  80.  
  81.                 $projContent += $source + "`"`r`n"
  82.             }
  83.            
  84.             Set-Content $gplproj -NoNewline -Value $projContent
  85.  
  86.             Write-Host "Compiling '$($gplproj)' to '$($target)'" -ForegroundColor Yellow
  87.             & $sdk '-in' $gplproj '-out' $target '-stderr'
  88.            
  89.             Remove-Item $gplproj
  90.         }
  91.     }
  92. }
  93.  
  94. # If running in the console, wait for input before closing.
  95. # Changed to require Space to be pressed, in case you have an error you need to copy.
  96. if ($Host.Name -eq "ConsoleHost")
  97. {
  98.     Write-Host "Press space to continue..."
  99.     While (($Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp")).Character -ne ' ') { }
  100. }
Add Comment
Please, Sign In to add comment