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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
"""Copy the proven Territory SimpleBillboardGlow texture. No synthesized pixels."""
from pathlib import Path
import gzip, hashlib, io, json, struct
from PIL import Image

source = Path('artifacts/galaxy-query-research/power-outer-sources/material')
image = Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe').read_bytes()
if hashlib.sha256(image).hexdigest() != '6891f70a021fa9f3a0e00458c284f48d1226e68ae7fc02ad48081aed47857e93':
    raise ValueError('Pinned original client changed')
pe = struct.unpack_from('<I', image, 0x3c)[0]
sections = pe + 24 + struct.unpack_from('<H', image, pe + 20)[0]
def original_bytes(rva, size):
    for index in range(struct.unpack_from('<H', image, pe + 6)[0]):
        _, start, length, raw = struct.unpack_from('<4I', image, sections + index * 40 + 8)
        if start <= rva and rva + size <= start + length:
            return image[raw + rva - start:raw + rva - start + size]
    raise ValueError('Original RVA outside file-backed sections')
# Actual format reader51D4E0: R9d input -> table4E2E500[input] -> native
# graphics-interface format argument. This establishes BC4 independently of
# a visually plausible decoder or the relative ordering of enum names.
if original_bytes(0x51d4fc, 10) != bytes.fromhex('418bc1488d0dfa0f9104') or original_bytes(0x51d511, 4) != bytes.fromhex('448b2481'):
    raise ValueError('Original graphics format reader changed')
format_table = 0x51d506 + struct.unpack('<i', original_bytes(0x51d502, 4))[0]
if format_table != 0x4e2e500 or struct.unpack('<I', original_bytes(format_table + 101 * 4, 4))[0] != 80:
    raise ValueError('Original format101 is not DXGI80/BC4_UNorm')
metadata = json.loads((source / 'original-materials.json').read_text())
body = (source / (metadata['resource'] + '.stream0')).read_bytes()
if hashlib.sha256(body).hexdigest() != metadata['frozenSha256']:
    raise ValueError('Original material bundle changed')
material = next(m for m in metadata['materials'] if m['name'] == 'simplebillboardglow')
if material['shaderClass'] != 'GalaxyMapSimpleBillboard' or len(material['textures']) != 1:
    raise ValueError('Original Territory material changed')
appearance = {}
exec(Path('research/Extract-OriginalGalaxyAppearance.py').read_text().split('tables={}')[0], appearance)
configuration = (295, 14000)
label = appearance['string'](appearance['references'][(configuration[0], configuration[1] + 0x110)])
if label != 'SimpleBillboardGlow':
    raise ValueError('The actual renderer+110 material is no longer SimpleBillboardGlow')
texture = next(t for t in metadata['textures'] if t['name'] == 'simplebillboardglow.palphatexture')
if material['textures'][0]['binding']['id'] != texture['id']:
    raise ValueError('Original Territory texture binding changed')
if (texture['sourceFormat'], texture['width'], texture['height'], texture['depth'], texture['array'], texture['mips']) != (101, 512, 512, 1, 1, 10):
    raise ValueError('Original Territory texture dimensions changed')
payload = body[texture['gpuOffset']:texture['gpuOffset'] + texture['gpuBytes']]
if len(payload) != 181248:
    raise ValueError('Original Territory payload changed')
# Its first mip has128 rows of128 eight-byte BC4 blocks. Preserve row padding.
first = texture['mipLayout'][0]
if (first['rowPitch'], first['sliceBytes']) != (1024, 131072):
    raise ValueError('Original BC4 block layout changed')
dds = (b'DDS ' + struct.pack('<7I', 124, 0x81007, 512, 512, 131072, 0, 1) + bytes(44)
       + struct.pack('<8I', 32, 4, int.from_bytes(b'ATI1', 'little'), 0, 0, 0, 0, 0)
       + struct.pack('<5I', 0x1000, 0, 0, 0, 0) + payload[:131072])
Image.open(io.BytesIO(dds)).convert('RGB').save(source / 'original-territory-glow.png')
out = Path('XFEEDToolBox.Core/Rendering')
with (out / 'original-territory-glow.bc4.gz').open('wb') as stream:
    with gzip.GzipFile(filename='', mode='wb', fileobj=stream, mtime=0, compresslevel=9) as compressed:
        compressed.write(payload)
result = dict(sourceResource=metadata['resource'], sourceArchiveSha256=metadata['sourceArchiveSha256'],
              frozenSha256=metadata['frozenSha256'], sourceTexture=texture['name'], sourceFormat=101,
              rendererConfiguration=dict(sourceResource=appearance['key'], pool=295, offset=14000, field='0x110', label=label),
              shaderClass=material['shaderClass'], format='BC4_UNorm', nativeFormat=80,
              formatTableRva=hex(format_table), formatReaderRva='0x51d4e0', width=512, height=512, mipCount=10,
              mips=texture['mipLayout'], payloadBytes=len(payload), payloadSha256=hashlib.sha256(payload).hexdigest(),
              gameProcessAccess=False, gameCalls=0,
              notes='Original alpha texture only; prepared frame fade, shared RGB multiplier and final HDR output are separate evidence.')
(out / 'original-territory-glow.json').write_text(json.dumps(result, indent=2) + '\n')
print(json.dumps(dict(payloadSha256=result['payloadSha256'], compressedBytes=(out / 'original-territory-glow.bc4.gz').stat().st_size)))