Files
donnyandClaude Opus 5.5 b6ef8a31bc core: ygol_query_prompt_context names the effect that asks a prompt (TICKET-451, v1.7.0)
field::execute_cost / execute_target / execute_operation push the running
effect (handler, description, stable index, phase 1 / 2 / 3, chain link) on
core.ygol_running at step 0 and pop it when the function finishes; the
innermost entry is the effect that asks. effect::ygol_script_index is stamped
in card::add_effect while the card loads (initial_effect.size()), 0xffff
otherwise. The export writes 22 bytes; a handler the asking player does not
control and that is not face-up answers code 0, index 0xffff, description 0.
Export gates 335 / 856 / 850 -> 336 / 857 / 851.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 16:05:08 -07:00

145 lines
8.3 KiB
PowerShell

<#
Build ygol-engine.dll (x64, Release) for Windows.
One library: the duel server (server/) with the rules core (core/) linked
inside, exporting the core C API, start_server and stop_server. The build
is upstream's exec_windows_pro3 job: premake vs2022 in server/, then
MSBuild on build\YGOPro.sln, target ygoserver.
Needs: premake5 5.0.0-beta8 (-Premake), VS 2022 Build Tools with the C++
workload and a Windows 10 SDK, and a repo path WITHOUT spaces: libevent's
premake emits an unquoted xcopy prebuild step that splits on a space.
-Version <tag> is what ygol_engine_version() returns ("local" when not given).
Before building, the script checks contract\ocgapi.h: it must be core\ocgapi.h
verbatim plus the server's YGOSERVER_API lines from gframe\serverapi.h in its
marked block; a difference fails the build (the contract is a copy kept honest).
After the gate it writes out\win64\engine.json: { version, exports, protocol,
capabilities, binding }, protocol and capabilities READ from gframe\network.h and
the SendServerCapability line of single_duel.cpp / tag_duel.cpp, never typed in;
binding is the version of the C# binding released with this engine (the same tag).
Output: out\win64\ygol-engine.dll (+ .pdb). The export gate is the truth:
the script FAILS unless the DLL exports exactly 336 symbols (start_server,
stop_server, ygol_engine_version, and the core C API re-exported, ygol_sb_*
and ygol_preview_attack included). The Unity repo's old ygoserver.dll had 327:
its own core copy never carried patch 0008's six ygol_sb_* exports.
#>
[CmdletBinding()]
param(
[string]$Premake = "C:\premake\premake5.exe",
[string]$Version = "local",
[int]$ExpectedExports = 336
)
$ErrorActionPreference = "Stop"
$repo = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$server = Join-Path $repo "server"
$outDir = Join-Path $repo "out\win64"
if ($repo -match "\s") {
throw "The repo path '$repo' contains a space. libevent's unquoted xcopy prebuild step cannot run from it. Clone the repo to a space-free path (for example C:\ygol-engine)."
}
foreach ($p in @(@($Premake, "premake5"), @((Join-Path $server "premake5.lua"), "server premake"), @((Join-Path $repo "core\ocgapi.h"), "core"))) {
if (-not (Test-Path $p[0])) { throw "$($p[1]) not found at $($p[0])" }
}
$ver = & $Premake --version
if ($ver -notmatch "5\.0\.0-beta8") { Write-Warning "premake is '$ver'; the build is verified with 5.0.0-beta8." }
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not (Test-Path $vswhere)) { throw "vswhere not found at $vswhere (install VS 2022 Build Tools)" }
$vs = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
$msbuild = Join-Path $vs "MSBuild\Current\Bin\MSBuild.exe"
if (-not (Test-Path $msbuild)) { throw "MSBuild not found at $msbuild" }
$dumpbin = Get-ChildItem "$vs\VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $dumpbin) { throw "dumpbin not found under $vs (install the C++ workload)" }
# The contract header is a copy of two sources; refuse to build when it drifted.
$contractPath = Join-Path $repo "contract\ocgapi.h"
$contract = [IO.File]::ReadAllText($contractPath) -replace "`r`n", "`n"
$coreHeader = [IO.File]::ReadAllText((Join-Path $repo "core\ocgapi.h")) -replace "`r`n", "`n"
$blockStart = $contract.IndexOf("// --- server exports")
$blockEnd = $contract.IndexOf("// --- end server exports ---`n")
if ($blockStart -lt 0 -or $blockEnd -lt 0) { throw "contract\ocgapi.h has no server exports block" }
$blockEnd += "// --- end server exports ---`n".Length
$block = $contract.Substring($blockStart, $blockEnd - $blockStart)
$withoutBlock = $contract.Substring(0, $blockStart) + $contract.Substring($blockEnd)
$withoutBlock = $withoutBlock -replace "(?s)\A// contract/ocgapi.h:.*?`n(?=/\*)", ""
$withoutBlock = $withoutBlock -replace "`n`n#endif /\* OCGAPI_H_ \*/`n\z", "`n#endif /* OCGAPI_H_ */`n"
if ($withoutBlock -ne $coreHeader) { throw "contract\ocgapi.h differs from core\ocgapi.h outside the server exports block; update the contract copy" }
$serverLines = @(Get-Content (Join-Path $server "gframe\serverapi.h") | Where-Object { $_ -match "^\s*YGOSERVER_API\s+\S.*;" } | ForEach-Object { $_.Trim() })
$blockLines = @($block -split "`n" | Where-Object { $_ -match "^\s*YGOSERVER_API\s+\S.*;" } | ForEach-Object { $_.Trim() })
if ($serverLines.Count -eq 0) { throw "no YGOSERVER_API declarations found in gframe\serverapi.h" }
if (($serverLines -join "`n") -ne ($blockLines -join "`n")) { throw "contract\ocgapi.h server exports block differs from gframe\serverapi.h:`n serverapi.h: $($serverLines -join ' | ')`n contract: $($blockLines -join ' | ')" }
Write-Host "contract\ocgapi.h matches core\ocgapi.h + serverapi.h ($($serverLines.Count) server exports)"
# engine.json facts, read from the server source.
$networkH = Get-Content (Join-Path $server "gframe\network.h")
$protoLine = $networkH | Where-Object { $_ -match "^constexpr uint16_t FEATURE_PROTOCOL = (\d+);" } | Select-Object -First 1
if (-not $protoLine) { throw "FEATURE_PROTOCOL not found in gframe\network.h" }
$protocol = [int]$Matches[1]
$bits = @{}
foreach ($l in $networkH) { if ($l -match "^constexpr uint32_t (FEATURE_[A-Z_]+) = (0x[0-9A-Fa-f]+);") { $bits[$Matches[1]] = [Convert]::ToUInt32($Matches[2], 16) } }
$capExprs = @()
foreach ($f in @("single_duel.cpp", "tag_duel.cpp")) {
$l = Get-Content (Join-Path $server "gframe\$f") | Where-Object { $_ -match "^\s*cap\.flags = (.+?);" } | Select-Object -First 1
if (-not $l) { throw "cap.flags line not found in gframe\$f" }
$capExprs += ($Matches[1] -replace "\s", "")
}
if ($capExprs[0] -ne $capExprs[1]) { throw "single_duel.cpp and tag_duel.cpp advertise different capability flags" }
[uint32]$capabilities = 0
foreach ($name in ($capExprs[0] -split "\|")) {
if (-not $bits.ContainsKey($name)) { throw "capability $name has no constexpr uint32_t in gframe\network.h" }
$capabilities = $capabilities -bor $bits[$name]
}
$buildStart = Get-Date
Push-Location $server
try {
# Always from scratch: MSBuild's incremental check once reused an object
# older than the source change that mattered, and the DLL still built.
foreach ($d in @("obj", "bin", "build")) {
if (Test-Path $d) { Remove-Item $d -Recurse -Force }
}
# Upstream's server branch configures through the environment.
$env:SERVER_PRO3_SUPPORT = "1"
$env:LOG_IN_CHAT = "1"
$env:USE_SIMD = "best"
$env:YGOL_ENGINE_VERSION = $Version
Write-Host "==> premake vs2022"
& $Premake vs2022
if ($LASTEXITCODE -ne 0) { throw "premake failed" }
Write-Host "==> msbuild ygoserver (Release x64)"
& $msbuild "build\YGOPro.sln" /t:ygoserver /p:Configuration=Release /p:Platform=x64 /m /v:minimal /nologo
if ($LASTEXITCODE -ne 0) { throw "build failed" }
foreach ($o in @("obj\x64\Release\ygoserver\netserver.obj", "obj\x64\Release\ocgcore\ocgapi.obj")) {
if (-not (Test-Path $o)) { throw "$o was never produced; the build did not compile it" }
if ((Get-Item $o).LastWriteTime -lt $buildStart) { throw "$o is older than this run; the tree was not rebuilt" }
}
}
finally { Pop-Location }
$dll = Join-Path $server "bin\release\x64\ygol-engine.dll"
if (-not (Test-Path $dll)) { throw "built library not found at $dll" }
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
Copy-Item $dll $outDir -Force
$pdb = [IO.Path]::ChangeExtension($dll, ".pdb")
if (Test-Path $pdb) { Copy-Item $pdb $outDir -Force }
$out = Join-Path $outDir "ygol-engine.dll"
$n = ((& $dumpbin.FullName /exports $out) | Select-String -Pattern '^\s+\d+\s+[0-9A-F]+\s+[0-9A-F]{8}\s+(\w+)').Count
Write-Host ""
Write-Host "Built: $out"
Write-Host "exports: $n (expected $ExpectedExports)"
if ($n -ne $ExpectedExports) { throw "export count $n != $ExpectedExports; do NOT ship this build" }
$json = "{`n `"version`": `"$Version`",`n `"exports`": $n,`n `"protocol`": $protocol,`n `"capabilities`": $capabilities,`n `"binding`": `"$Version`"`n}`n"
[IO.File]::WriteAllText((Join-Path $outDir "engine.json"), $json, (New-Object Text.UTF8Encoding $false))
Write-Host "engine.json: version $Version, exports $n, protocol $protocol, capabilities 0x$($capabilities.ToString('X')), binding $Version"