XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
"""Decode original UI atlases and resolve them in private JPEXS research copies."""
import hashlib
import io
import json
import struct
import xml.etree.ElementTree as ET
from pathlib import Path
from PIL import Image

root=Path('artifacts/galaxy-marker-research')
body=(root/'map.bin').read_bytes()
group_count=19
buffers=[struct.unpack_from('<II',body,716+i*8) for i in range(36)]
groups=[]
cursor=0
for i in range(group_count):
    count=struct.unpack_from('<H',body,108+i*32+10)[0]
    groups.append(buffers[cursor:cursor+count]);cursor+=count
if cursor!=36:raise ValueError('Unexpected original map buffer layout')
payload=len(body)-sum(size for _,size in buffers)
if payload!=10148:raise ValueError('Unexpected original map payload offset')
atlas_specs={6:('MapUI_I139',2048,2048),7:('MapUI_I191',2048,1948)}
rows=[]
offset=payload
for column in range(max(map(len,groups))):
    for group,parts in enumerate(groups):
        if len(parts)<=column:continue
        _,size=parts[column]
        if group in atlas_specs and size:
            name,width,height=atlas_specs[group]
            if size!=width*height:raise ValueError('Unexpected BC7 atlas dimensions')
            gpu=body[offset:offset+size]
            dds=(b'DDS '+struct.pack('<7I',124,0x81007,height,width,len(gpu),0,1)+bytes(44)
                 +struct.pack('<8I',32,4,int.from_bytes(b'DX10','little'),0,0,0,0,0)
                 +struct.pack('<5I',0x1000,0,0,0,0)+struct.pack('<5I',98,3,0,1,0))
            image=Image.open(io.BytesIO(dds+gpu)).convert('RGBA')
            image.save(root/(name+'.png'))
            rows.append(dict(name=name,width=width,height=height,bufferGroup=group,gpuOffset=offset,gpuBytes=size,
                gpuSha256=hashlib.sha256(gpu).hexdigest(),rgbaSha256=hashlib.sha256(image.tobytes()).hexdigest()))
        offset+=size
if offset!=len(body) or len(rows)!=2:raise ValueError('Incomplete original atlas extraction')
tree=ET.parse(root/'map-gfx.xml')
for element in tree.getroot().iter():
    if element.attrib.get('type')=='DefineExternalImage2':
        name=element.attrib.get('fileName','')
        if name in ('MapUI_I139.dds','MapUI_I191.dds'):element.attrib['fileName']=name[:-4]+'.png'
tree.write(root/'map-render.xml',encoding='utf-8',xml_declaration=True)
(root/'map-atlas-evidence.json').write_text(json.dumps(rows,indent=2)+'\n',encoding='utf-8')
print(json.dumps(rows,indent=2))