45 lines
3.4 KiB
Python
45 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
import sys,subprocess,json,struct,tempfile,os
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
if len(sys.argv)>1 and sys.argv[1]=='--build':
|
|
out=Path(sys.argv[2]).resolve();out.mkdir(parents=True,exist_ok=True)
|
|
subprocess.run(['dotnet','build',str(ROOT/'ops/db2-bake-20261122/tool/Db2Bake.csproj'),'-o',str(out/'db2-bake'),'-p:BaseIntermediateOutputPath='+str(out/'db2-obj')+'/', '-p:RestoreConfigFile='+str(ROOT/'ops/hotfix_baked_audit/NuGet.Config'),'-p:NuGetAudit=false','--verbosity','quiet','--nologo'],check=True)
|
|
casc=Path('/mnt/Games/@project/tools/casc-tool')
|
|
subprocess.run(['c++','-std=c++17','-O2','-Wall','-Wextra','-Werror','-I',str(casc/'vendor/CascLib/src'),str(ROOT/'ops/addon_source_authority/CascRootRead.cpp'),str(casc/'build/vendor/CascLib/libcasc.a'),'-lz','-pthread','-o',str(out/'casc-root-read')],check=True)
|
|
raise SystemExit(0)
|
|
sys.path.insert(0,str(ROOT/'ops'));from addon_source_authority import classify,dbc,image_mips,run,icon_authority,select_variant
|
|
assert select_variant([{'archive':'patch-5.mpq','sha256':'a'},{'archive':'patch-O.mpq','sha256':'b'}])['sha256']=='b'
|
|
try:select_variant([{'archive':'dbc.MPQ','sha256':'a'},{'archive':'base.MPQ','sha256':'b'}])
|
|
except ValueError:pass
|
|
else:raise AssertionError('ambiguous base assets accepted')
|
|
assert classify([1],[2],[1])=='addon-correct'
|
|
assert classify([1],[2],[2])=='DB2-correct'
|
|
assert classify([1],[2],[3])=='both-wrong'
|
|
assert classify([1],[1],[1])=='both-correct'
|
|
with tempfile.TemporaryDirectory() as d:
|
|
p=Path(d)/'test.dbc';p.write_bytes(b'WDBC'+struct.pack('<4I',1,2,8,3)+struct.pack('<2I',7,1)+b'\0x\0')
|
|
rows,text=dbc(p,2);assert rows[7][1]==1 and text(1)=='x'
|
|
try:dbc(p,3)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Wrong source schema accepted')
|
|
# All authored mips participate; unrelated encoding metadata does not.
|
|
def bgra(pixel):
|
|
return b'BLP2'+struct.pack('<I4BII',1,3,8,0,1,1,1)+struct.pack('<16I',148,*([0]*15))+struct.pack('<16I',4,*([0]*15))+bytes(pixel)
|
|
a=bgra([1,2,3,255]);b=bgra([1,2,4,255]);assert image_mips(a)['sha256']!=image_mips(b)['sha256']
|
|
# The observed Source BC1 exporter defect is confined to impossible post-1x1 slots.
|
|
sizes=[2048,512,128,32,8,8,8];offsets=[];offset=1172
|
|
for size in sizes:offsets.append(offset);offset+=size
|
|
raw=bytearray(b'BLP2'+struct.pack('<I4BII',1,2,1,0,1,64,64)+struct.pack('<16I',*offsets,*([0]*9))+struct.pack('<16I',*sizes,*([0]*9))+bytes(offset-148))
|
|
clean=image_mips(bytes(raw));struct.pack_into('<I',raw,20+7*4,len(raw));struct.pack_into('<I',raw,84+7*4,(-len(raw))&0xffffffff);struct.pack_into('<I',raw,84+15*4,sizes[0])
|
|
observed=image_mips(bytes(raw));assert observed['sha256']==clean['sha256'] and observed['unused_directory_normalization_required']
|
|
struct.pack_into('<I',raw,20+8*4,1)
|
|
try:image_mips(bytes(raw))
|
|
except ValueError:pass
|
|
else:raise AssertionError('Unrecognized unused-directory damage accepted')
|
|
if os.environ.get('GW_ADDON_SOURCE_AUTHORITY_ROOT'):
|
|
artifact=Path(os.environ['GW_ADDON_SOURCE_AUTHORITY_ROOT']);run(artifact);icon_authority(artifact)
|
|
sys.path.insert(0,str(ROOT/'ops/addon_source_authority'));from verify import verify
|
|
verify(artifact,artifact.parent/'hotfix-baked-audit-46/installed-db2',Path(os.environ['GW_ADDON_SOURCE_AUTHORITY_READER']),Path('/mnt/Games/@project/tools/WoWDBDefs/definitions'))
|
|
print('PASS Source authority classification, DBC schema, and full-mip pixel identity')
|