param([switch]$NewUltraPara, [string]$GameDir = "C:\Program Files (x86)\Steam\steamapps\common\Casualties Unknown") $ErrorActionPreference = "Stop" $root = $PSScriptRoot $M = Join-Path $GameDir "CasualtiesUnknown_Data\Managed" $csc = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" $obj = Join-Path $root "obj" $outDir = Join-Path $root "bin" New-Item -ItemType Directory -Force $obj, $outDir | Out-Null $lib = Join-Path $root "lib" $libs = @("0Harmony","MonoMod.RuntimeDetour","MonoMod.Utils","Mono.Cecil") $refs = @() foreach ($n in @("mscorlib","System","System.Core","netstandard","UnityEngine","UnityEngine.CoreModule","UnityEngine.Physics2DModule","UnityEngine.InputLegacyModule","UnityEngine.AudioModule","UnityEngine.UnityWebRequestModule","UnityEngine.UnityWebRequestAudioModule","UnityEngine.UI","UnityEngine.UIModule","UnityEngine.ImageConversionModule","UnityEngine.TextRenderingModule","Unity.TextMeshPro","Assembly-CSharp")) { $p = Join-Path $M "$n.dll" if (-not (Test-Path $p)) { throw "missing $p" } $refs += "/r:`"$p`"" } $refs += "/r:`"$(Join-Path $lib '0Harmony.dll')`"" $res = @() foreach ($n in $libs) { $p = Join-Path $lib "$n.dll" if (-not (Test-Path $p)) { throw "missing $p" } $res += "/resource:`"$p`",lib.$n.dll" } $payload = Join-Path $obj "Payload.dll" $pa = @("/nologo","/nostdlib+","/noconfig","/target:library","/langversion:5","/optimize+","/out:`"$payload`"") + $refs + $res + @("`"$(Join-Path $root 'src\Payload.cs')`"","`"$(Join-Path $root 'src\Engine.cs')`"","`"$(Join-Path $root 'src\Health.cs')`"","`"$(Join-Path $root 'src\Debug.cs')`"","`"$(Join-Path $root 'src\MyMods.cs')`"","`"$(Join-Path $root 'src\Music.cs')`"") & $csc $pa if ($LASTEXITCODE -ne 0) { throw "payload build failed" } $upRoot = (Resolve-Path (Join-Path $root "..\UltraPara")).Path if ($NewUltraPara -or -not (Test-Path (Join-Path $upRoot "out\UltraParaInfo.cs"))) { & powershell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $upRoot "build.ps1") -GameDir $GameDir if ($LASTEXITCODE -ne 0) { throw "UltraPara build failed" } } else { Write-Host "Keeping the published UltraPara build (use -NewUltraPara after changing game-side code)" } $upInfo = Join-Path $upRoot "out\UltraParaInfo.cs" $ico = Join-Path $obj "app.ico" $splashJpg = Join-Path $root "art\splash.jpg" Add-Type -AssemblyName System.Drawing $head = [System.Drawing.Bitmap]::FromFile((Join-Path $root "art\experimentHead.png")) $hw = 20; $hh = 12 $orange = [System.Drawing.Color]::FromArgb(255, 122, 24) function New-Tile([int]$s) { $bmp = New-Object System.Drawing.Bitmap $s, $s $g = [System.Drawing.Graphics]::FromImage($bmp) $g.SmoothingMode = "AntiAlias" $r = [Math]::Max(1, [int]($s * 0.16)) $path = New-Object System.Drawing.Drawing2D.GraphicsPath $path.AddArc(0, 0, $r * 2, $r * 2, 180, 90); $path.AddArc($s - $r * 2 - 1, 0, $r * 2, $r * 2, 270, 90) $path.AddArc($s - $r * 2 - 1, $s - $r * 2 - 1, $r * 2, $r * 2, 0, 90); $path.AddArc(0, $s - $r * 2 - 1, $r * 2, $r * 2, 90, 90) $path.CloseFigure() $br = New-Object System.Drawing.SolidBrush $orange $g.FillPath($br, $path) $br.Dispose(); $path.Dispose() $scale = [Math]::Floor(($s * 0.86) / $hw) $g.SmoothingMode = "None" if ($scale -ge 1) { $g.InterpolationMode = "NearestNeighbor"; $g.PixelOffsetMode = "Half" $w = $hw * $scale; $h = $hh * $scale } else { $g.InterpolationMode = "HighQualityBicubic"; $g.PixelOffsetMode = "HighQuality" $w = [int]($s * 0.86); $h = [int]($w * $hh / $hw) } $w = [int]$w; $h = [int]$h $x = [int][Math]::Floor(($s - $w) / 2); $y = [int][Math]::Floor(($s - $h) / 2) $dst = New-Object System.Drawing.Rectangle -ArgumentList $x, $y, $w, $h $srcR = New-Object System.Drawing.Rectangle -ArgumentList 0, 0, $hw, $hh $g.DrawImage([System.Drawing.Image]$script:head, $dst, $srcR, [System.Drawing.GraphicsUnit]::Pixel) $g.Dispose() return $bmp } $pngs = @() foreach ($s in 256, 64, 48, 32, 24, 16) { $bmp = New-Tile $s $ms = New-Object System.IO.MemoryStream if ($s -eq 256) { $bmp.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png) $bmp.Save((Join-Path $root "art\icon.png"), [System.Drawing.Imaging.ImageFormat]::Png) } else { $dib = New-Object System.IO.BinaryWriter $ms $dib.Write([uint32]40); $dib.Write([int32]$s); $dib.Write([int32]($s * 2)); $dib.Write([uint16]1); $dib.Write([uint16]32) $dib.Write([uint32]0); $dib.Write([uint32]($s * $s * 4)); $dib.Write([int32]0); $dib.Write([int32]0); $dib.Write([uint32]0); $dib.Write([uint32]0) for ($yy = $s - 1; $yy -ge 0; $yy--) { for ($xx = 0; $xx -lt $s; $xx++) { $c = $bmp.GetPixel($xx, $yy) $dib.Write([byte]$c.B); $dib.Write([byte]$c.G); $dib.Write([byte]$c.R); $dib.Write([byte]$c.A) } } $maskRow = [int]([Math]::Ceiling($s / 32.0) * 4) $dib.Write((New-Object byte[] ($maskRow * $s))) $dib.Flush() } $bmp.Dispose() $pngs += ,@($s, $ms.ToArray()) } $tile = New-Tile 48 $tilePng = Join-Path $obj "tile.png" $tile.Save($tilePng, [System.Drawing.Imaging.ImageFormat]::Png) $tile.Dispose() $head.Dispose() $fs = [System.IO.File]::Create($ico) $bw = New-Object System.IO.BinaryWriter $fs $bw.Write([uint16]0); $bw.Write([uint16]1); $bw.Write([uint16]$pngs.Count) $offset = 6 + 16 * $pngs.Count foreach ($p in $pngs) { $sz = $p[0]; $data = $p[1] $bw.Write([byte]($sz % 256)); $bw.Write([byte]($sz % 256)); $bw.Write([byte]0); $bw.Write([byte]0) $bw.Write([uint16]1); $bw.Write([uint16]32); $bw.Write([uint32]$data.Length); $bw.Write([uint32]$offset) $offset += $data.Length } foreach ($p in $pngs) { $bw.Write([byte[]]$p[1]) } $bw.Close() $exe = Join-Path $outDir "Ultra Paradise CU-Trainer.exe" $old = Join-Path $outDir "Ultra Paradise.exe" if (Test-Path $old) { Remove-Item $old } $fw = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319" $winmd = Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\UnionMetadata" -Directory | Where-Object { $_.Name -match "^\d" } | Sort-Object { [version]$_.Name } -Descending | ForEach-Object { Join-Path $_.FullName "Windows.winmd" } | Where-Object { Test-Path $_ } | Select-Object -First 1 if (-not $winmd) { throw "missing Windows.winmd (Windows SDK)" } $a = @("/nologo","/target:winexe","/platform:x64","/langversion:5","/optimize+","/win32icon:`"$ico`"","/out:`"$exe`"", "/r:`"$fw\System.dll`"","/r:`"$fw\System.Drawing.dll`"","/r:`"$fw\System.Windows.Forms.dll`"","/r:`"$fw\System.Web.Extensions.dll`"","/r:`"$fw\System.IO.Compression.dll`"","/r:`"$fw\System.IO.Compression.FileSystem.dll`"","/r:`"$fw\System.Xaml.dll`"","/r:`"$fw\WPF\PresentationCore.dll`"","/r:`"$fw\WPF\WindowsBase.dll`"","/r:`"$winmd`"","/r:`"$fw\System.Runtime.WindowsRuntime.dll`"","/r:`"$fw\System.Runtime.dll`"","/r:`"$fw\System.Threading.Tasks.dll`"","/r:`"$fw\System.Runtime.InteropServices.WindowsRuntime.dll`"", "/resource:`"$splashJpg`",UltraParadise.splash.jpg","/resource:`"$tilePng`",UltraParadise.tile.png","/resource:`"$(Join-Path $root 'art\logo-nexus.png')`",UltraParadise.logo-nexus.png","/resource:`"$(Join-Path $root 'art\logo-gamebanana.png')`",UltraParadise.logo-gamebanana.png","/resource:`"$(Join-Path $root 'art\logo-discord.png')`",UltraParadise.logo-discord.png", "`"$(Join-Path $root 'src\Trainer.cs')`"","`"$(Join-Path $root 'src\Theme.cs')`"","`"$(Join-Path $root 'src\DebugWindow.cs')`"","`"$(Join-Path $root 'src\Loader.cs')`"","`"$(Join-Path $root 'src\MyModsPanel.cs')`"","`"$(Join-Path $root 'src\MusicTab.cs')`"","`"$(Join-Path $root 'src\NowPlaying.cs')`"","`"$(Join-Path $root 'src\Tools.cs')`"","`"$(Join-Path $root 'src\Lyrics.cs')`"","`"$(Join-Path $root 'src\Thunderstore.cs')`"","`"$upInfo`"") & $csc $a if ($LASTEXITCODE -ne 0) { throw "trainer build failed" } Write-Host ("payload {0} bytes, exe {1} bytes" -f (Get-Item $payload).Length, (Get-Item $exe).Length)