Files
bdot89andClaude Opus 5.5 c968efaf7e 2.21.4: ported preview framing ships with DMorph; no re-pack needed
User: friends shouldn't have to do anything. The ported frame data is only
numbers per display ID, so it's Data/PortedFrames.lua in DMorph, tagged
with the pack's ID and only used when the pack matches. The pack and
install scripts are back as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 00:36:40 +01:00

117 lines
5.7 KiB
PowerShell

param(
[string]$GameDir = (Resolve-Path (Join-Path $PSScriptRoot "..\..\..\..")).Path,
[string]$OutFile = (Join-Path $PSScriptRoot "..\Data\ModelFrames.lua"),
# Also the ported models (archives marked DmorphPort.txt, only on the PC
# that made them), into Data/PortedFrames.lua: only numbers per display ID,
# so it ships with DMorph and friends with the same pack need nothing more.
[switch]$Ported,
[string]$PortedFile = (Join-Path $PSScriptRoot "..\Data\PortedFrames.lua"),
[string]$PortedList = (Join-Path $PSScriptRoot "..\..\DMorph_Ported\Ported.lua")
)
# Builds Data/ModelFrames.lua: how DMorph's previews frame each creature
# display so the whole model shows (the model's own portrait camera only
# shows its head). Per model file: what its portrait camera sees and how big
# the model is (GameFiles.Frame in MpqDbc.cs); per display: which model.
#
# powershell -ExecutionPolicy Bypass -File tools\build_frames.ps1 [-GameDir C:\Games\OctoWoW] [-Ported]
#
# Run by tools/update_from_game.ps1. Runs on Windows PowerShell 5.1.
$ErrorActionPreference = "Stop"
Add-Type -Path (Join-Path $PSScriptRoot "MpqDbc.cs")
# The client reads its MPQs in this order and later ones win: the base
# archives, patch.MPQ, then patch-1..9, then patch-A..Z.
function Get-Priority([string]$name) {
$base = [IO.Path]::GetFileNameWithoutExtension($name).ToLowerInvariant()
if ($base -eq "patch") { return 100 }
if ($base -match '^patch-([0-9])$') { return 100 + [int]$matches[1] }
if ($base -match '^patch-([a-z])$') { return 200 + [int][char]$matches[1] }
return 0
}
$dataDir = Join-Path $GameDir "Data"
if (-not (Test-Path $dataDir)) { throw "No Data folder in $GameDir" }
$public = @(); $all = @()
foreach ($file in Get-ChildItem $dataDir -Filter *.mpq) {
try {
$m = New-Object Mpq $file.FullName
$all += $m
# The model porting tool's archives are only on the PC that made them.
$mine = $file.Name -ieq "patch-Z.mpq" -or $file.Name -ieq "patch-Y.mpq" -or $m.Has("DmorphPort.txt")
if (-not $mine) { $public += $m }
} catch { Write-Output ("skipped {0}: {1}" -f $file.Name, $_.Exception.Message) }
}
function Build([object[]]$mpqs, [string]$out, [string]$variable, [scriptblock]$keep, [string]$pack = "") {
$mpqs = @($mpqs | Sort-Object @{ Expression = { Get-Priority $_.Name } }, Name)
$files = New-Object GameFiles (,[Mpq[]]$mpqs)
$read = {
param([string]$name)
for ($i = $mpqs.Count - 1; $i -ge 0; $i--) {
$bytes = $mpqs[$i].Read($name)
if ($bytes) { return New-Object Dbc (,$bytes) }
}
throw "$name is in none of the MPQs"
}
$display = & $read "DBFilesClient\CreatureDisplayInfo.dbc"
$modelData = & $read "DBFilesClient\CreatureModelData.dbc"
# CreatureModelData: 0 ID, 2 model path. CreatureDisplayInfo: 0 ID, 1 model.
$paths = @{}
for ($i = 0; $i -lt $modelData.Count; $i++) { $paths[$modelData.Int($i, 0)] = $modelData.Str($i, 2) }
$frames = @{}; $index = @{}; $rows = New-Object System.Collections.ArrayList
$pairs = New-Object System.Collections.ArrayList
$missing = 0; $count = 0
for ($i = 0; $i -lt $display.Count; $i++) {
$id = $display.Int($i, 0)
if (-not (& $keep $id)) { continue }
$path = $paths[$display.Int($i, 1)]
if (-not $path) { continue }
if (-not $frames.ContainsKey($path)) { $frames[$path] = $files.Frame($path) }
$frame = $frames[$path]
if (-not $frame) { $missing++; continue }
if (-not $index.ContainsKey($frame)) { $index[$frame] = $rows.Count + 1; [void]$rows.Add($frame) }
[void]$pairs.Add(@($id, $index[$frame]))
$count++
}
$sorted = $pairs | Sort-Object { $_[0] }
$sb = New-Object Text.StringBuilder
[void]$sb.Append("-- Generated by tools/build_frames.ps1 from the client's model files. Do not edit.`n")
[void]$sb.Append("-- Models: ""R Tx Ty Tz Cx Cy Cz height width"" per line (see GameFiles.Frame in tools/MpqDbc.cs);`n")
[void]$sb.Append("-- displays: ""display:model"" pairs, the model being a line number above.`n")
[void]$sb.Append("$variable = {`n")
# The pack these display IDs belong to (DmorphOcto.GetPortedPack); another pack ignores the file.
if ($pack) { [void]$sb.Append(" pack = ""$pack"",`n") }
[void]$sb.Append(" models = [[`n")
foreach ($row in $rows) { [void]$sb.Append($row).Append("`n") }
[void]$sb.Append("]],`n displays = [[`n")
$n = 0
foreach ($p in $sorted) {
[void]$sb.Append($p[0]).Append(":").Append($p[1])
$n++
if ($n % 20 -eq 0) { [void]$sb.Append("`n") } else { [void]$sb.Append(" ") }
}
[void]$sb.Append("`n]],`n}`n")
$dir = Split-Path $out -Parent
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force $dir | Out-Null }
[IO.File]::WriteAllText($out, $sb.ToString(), (New-Object Text.UTF8Encoding $false))
Write-Output ("{0}: {1} displays framed from {2} models, {3} without a readable model or camera" -f
(Split-Path $out -Leaf), $count, $rows.Count, $missing)
}
Build $public $OutFile "DmorphOcto_ModelFrames" { param($id) $true }
if ($Ported) {
# The pack ID as DMorph works it out: "P" and the rows of the models, items
# and sets lists in Ported.lua.
if (-not (Test-Path $PortedList)) { throw "No ported list at $PortedList" }
$lines = [IO.File]::ReadAllLines($PortedList)
$counts = @{}; $open = $null; $start = 0
for ($i = 0; $i -lt $lines.Count; $i++) {
if ($lines[$i] -match '^(DmorphOcto_Ported\w+) = \[\[$') { $open = $matches[1]; $start = $i }
elseif ($open -and $lines[$i] -match '^\]\]') { $counts[$open] = $i - $start - 1; $open = $null }
}
$pack = "P{0}x{1}x{2}" -f [int]$counts["DmorphOcto_PortedData"], [int]$counts["DmorphOcto_PortedItems"], [int]$counts["DmorphOcto_PortedSets"]
# Only the displays the porting tool added (60001 and up).
Build $all $PortedFile "DmorphOcto_PortedFrames" { param($id) $id -ge 60001 } $pack
}