cu-trainer/UltraPara/build.ps1
| 1 | param([string]$GameDir = "C:\Program Files (x86)\Steam\steamapps\common\Casualties Unknown") |
| 2 | $ErrorActionPreference = "Stop" |
| 3 | $root = $PSScriptRoot |
| 4 | $ver = "1.2.2" |
| 5 | $vcvars = "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvars64.bat" |
| 6 | if (-not (Test-Path $vcvars)) { $vcvars = "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" } |
| 7 | if (-not (Test-Path $vcvars)) { throw "missing vcvars64.bat" } |
| 8 | $obj = Join-Path $root "obj" |
| 9 | $out = Join-Path $root "out" |
| 10 | New-Item -ItemType Directory -Force $obj, $out | Out-Null |
| 11 | |
| 12 | $winPayload = (Resolve-Path (Join-Path $root "..\Ultra Paradise Application\obj\Payload.dll")).Path |
| 13 | & powershell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $root "..\Ultra Paradise Linux\plugin\build.ps1") -GameDir $GameDir |
| 14 | if ($LASTEXITCODE -ne 0) { throw "linux payload build failed" } |
| 15 | $linPayload = (Resolve-Path (Join-Path $root "..\Ultra Paradise Linux\plugin\bin\UltraParadise.CUTrainer.dll")).Path |
| 16 | |
| 17 | $v4 = ($ver.Replace(".", ",")) + ",0" |
| 18 | function New-Rc([string]$file, [string]$desc, [string]$name, [string]$extra) { |
| 19 | $rc = @" |
| 20 | #include <winver.h> |
| 21 | $extra |
| 22 | VS_VERSION_INFO VERSIONINFO |
| 23 | FILEVERSION $v4 |
| 24 | PRODUCTVERSION $v4 |
| 25 | FILEOS VOS_NT_WINDOWS32 |
| 26 | FILETYPE VFT_DLL |
| 27 | BEGIN |
| 28 | BLOCK "StringFileInfo" |
| 29 | BEGIN |
| 30 | BLOCK "040904b0" |
| 31 | BEGIN |
| 32 | VALUE "CompanyName", "casualexpie" |
| 33 | VALUE "FileDescription", "$desc" |
| 34 | VALUE "FileVersion", "$ver" |
| 35 | VALUE "InternalName", "$name" |
| 36 | VALUE "OriginalFilename", "$name" |
| 37 | VALUE "ProductName", "UltraPara" |
| 38 | VALUE "ProductVersion", "$ver" |
| 39 | VALUE "LegalCopyright", "Copyright (c) casualexpie. All rights reserved." |
| 40 | VALUE "Comments", "Do NOT decompile, disassemble, or reverse-engineer this file. Report bug symptoms on the Nexus Bugs page." |
| 41 | END |
| 42 | END |
| 43 | BLOCK "VarFileInfo" |
| 44 | BEGIN |
| 45 | VALUE "Translation", 0x409, 1200 |
| 46 | END |
| 47 | END |
| 48 | "@ |
| 49 | [IO.File]::WriteAllText($file, $rc, (New-Object Text.UTF8Encoding $false)) |
| 50 | } |
| 51 | $esc = { param($p) $p.Replace("\", "\\") } |
| 52 | New-Rc (Join-Path $obj "ultrapara.rc") "UltraPara loader for Ultra Paradise CU:Trainer" "UltraPara.dll" ("101 10 `"" + (& $esc $winPayload) + "`"`r`n102 10 `"" + (& $esc $linPayload) + "`"") |
| 53 | New-Rc (Join-Path $obj "version.rc") "UltraPara starter for Ultra Paradise CU:Trainer" "version.dll" "" |
| 54 | |
| 55 | $cmd = Join-Path $obj "build.cmd" |
| 56 | $src = Join-Path $root "src" |
| 57 | $lines = @( |
| 58 | "@echo off", |
| 59 | "call `"$vcvars`" >nul || exit /b 1", |
| 60 | "cd /d `"$obj`"", |
| 61 | "rc /nologo /fo ultrapara.res ultrapara.rc || exit /b 1", |
| 62 | "rc /nologo /fo version.res version.rc || exit /b 1", |
| 63 | "cl /nologo /O1 /MT /GS /W3 /DULTRAPARA_VER=\`"$ver\`" /c `"$src\ultrapara.c`" /Fo:ultrapara.obj || exit /b 1", |
| 64 | "cl /nologo /O1 /MT /GS /W3 /c `"$src\version.c`" /Fo:version.obj || exit /b 1", |
| 65 | "link /nologo /DLL /OUT:`"$out\UltraPara.dll`" ultrapara.obj ultrapara.res kernel32.lib || exit /b 1", |
| 66 | "link /nologo /DLL /DEF:`"$src\version.def`" /OUT:`"$out\version.dll`" version.obj version.res kernel32.lib || exit /b 1" |
| 67 | ) |
| 68 | [IO.File]::WriteAllText($cmd, ($lines -join "`r`n"), (New-Object Text.ASCIIEncoding)) |
| 69 | & cmd /c "`"$cmd`"" |
| 70 | if ($LASTEXITCODE -ne 0) { throw "native build failed" } |
| 71 | Remove-Item (Join-Path $out "*.lib"), (Join-Path $out "*.exp") -ErrorAction SilentlyContinue |
| 72 | |
| 73 | Get-ChildItem $out -Filter "UltraPara-*.zip" | Remove-Item |
| 74 | $zip = Join-Path $out "UltraPara-$ver.zip" |
| 75 | Add-Type -AssemblyName System.IO.Compression, System.IO.Compression.FileSystem |
| 76 | $fs = [IO.File]::Open($zip, [IO.FileMode]::Create) |
| 77 | $za = New-Object IO.Compression.ZipArchive($fs, [IO.Compression.ZipArchiveMode]::Create) |
| 78 | foreach ($n in "UltraPara.dll", "version.dll") { [IO.Compression.ZipFileExtensions]::CreateEntryFromFile($za, (Join-Path $out $n), $n) | Out-Null } |
| 79 | $za.Dispose(); $fs.Dispose() |
| 80 | |
| 81 | function Get-Sha([string]$p) { (Get-FileHash $p -Algorithm SHA256).Hash.ToLower() } |
| 82 | $info = @" |
| 83 | namespace UltraParadise |
| 84 | { |
| 85 | internal static class UltraParaInfo |
| 86 | { |
| 87 | public const string Version = "$ver"; |
| 88 | public const string ZipName = "UltraPara-$ver.zip"; |
| 89 | public const string ZipSha = "$(Get-Sha $zip)"; |
| 90 | public const string DllSha = "$(Get-Sha (Join-Path $out 'UltraPara.dll'))"; |
| 91 | public const string StubSha = "$(Get-Sha (Join-Path $out 'version.dll'))"; |
| 92 | } |
| 93 | } |
| 94 | "@ |
| 95 | [IO.File]::WriteAllText((Join-Path $out "UltraParaInfo.cs"), $info, (New-Object Text.UTF8Encoding $false)) |
| 96 | Write-Host ("UltraPara {0}: dll {1} bytes, stub {2} bytes, zip {3}" -f $ver, (Get-Item (Join-Path $out 'UltraPara.dll')).Length, (Get-Item (Join-Path $out 'version.dll')).Length, (Get-Sha $zip)) |