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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
"""Copy the original SectorLine BC7 texture and its source style. No game calls."""
from pathlib import Path
import gzip,hashlib,io,json,struct
from PIL import Image

root=Path('artifacts/galaxy-query-research/power-outer-sources')
image=Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe').read_bytes()
expected='6891f70a021fa9f3a0e00458c284f48d1226e68ae7fc02ad48081aed47857e93'
if hashlib.sha256(image).hexdigest()!=expected:raise ValueError('Pinned original image 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 i in range(struct.unpack_from('<H',image,pe+6)[0]):
        _,start,length,raw=struct.unpack_from('<4I',image,sections+i*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')
if original_bytes(0x51d4fc,10)!=bytes.fromhex('418bc1488d0dfa0f9104') or original_bytes(0x51d511,4)!=bytes.fromhex('448b2481'):
    raise ValueError('Original graphics format reader changed')
if struct.unpack('<I',original_bytes(0x4e2e500+107*4,4))[0]!=98:raise ValueError('Original format107 is not DXGI98/BC7_UNorm')
if original_bytes(0x551f708,11)!=b'%s_nodepth\0':raise ValueError('Original SectorLine suffix changed')
if struct.unpack('<Q',original_bytes(0x551ef18+0x10,8))[0]!=0x143aac040:raise ValueError('Original grid named publisher changed')

source=root/'material';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 source changed')
appearance={};exec(Path('research/Extract-OriginalGalaxyAppearance.py').read_text().split('# Federation row')[0],appearance)
b=appearance['b'];at=appearance['at'];refs=appearance['references'];cfg=(295,14000)
if hashlib.sha256(b).hexdigest()!='5135b3d55e5239b3d11f79a76adeda954eb78be5101b6a516fd25df257affa77':raise ValueError('Original render configuration changed')
label=appearance['string'](refs[cfg[0],cfg[1]+0xf8])
if label!='SectorLine':raise ValueError('Actual viewport8 material changed')
style=refs[cfg[0],cfg[1]+0x1a0];s=at(style)
rgba=list(struct.unpack_from('<4f',b,s+4));width=struct.unpack_from('<f',b,s+0x18)[0]
uv=[b[s+0x30],b[at(cfg)+0x1a8],struct.unpack_from('<f',b,s+0x14)[0],0]
fade=list(struct.unpack_from('<4f',b,at(refs[cfg[0],cfg[1]+0x98])))
if uv!=[0,8,1,0] or width!=struct.unpack('<f',bytes.fromhex('0ad7a33c'))[0]:raise ValueError('Original line style changed')
material=next(m for m in metadata['materials'] if m['name']=='sectorline_nodepth')
texture=next(t for t in metadata['textures'] if t['name']=='sectorline_nodepth.pdiffusetexture')
if material['shaderClass']!='StarMapLine' or material['textures'][0]['binding']['id']!=texture['id']:raise ValueError('Original SectorLine shader binding changed')
if (texture['sourceFormat'],texture['width'],texture['height'],texture['mips'],texture['array'])!=(107,512,512,10,1):raise ValueError('Original line texture changed')
payload=body[texture['gpuOffset']:texture['gpuOffset']+texture['gpuBytes']]
if len(payload)!=353280:raise ValueError('Original line texture length changed')
out=Path('XFEEDToolBox.Core/Rendering')
(out/'original-grid-line.bc7.gz').write_bytes(gzip.compress(payload,compresslevel=9,mtime=0))
result=dict(imageSha256=expected,sourceResource=metadata['resource'],sourceArchiveSha256=metadata['sourceArchiveSha256'],
    frozenSha256=metadata['frozenSha256'],configurationResource=appearance['key'],configurationSha256=hashlib.sha256(b).hexdigest(),
    material=material,configurationField='0xf8',configurationLabel=label,viewportSlot=8,styleField='0x1a0',stylePointer=style,
    styleRaw=b[s:s+56].hex(),rgba=rgba,baseHalfWidth=width,uv=uv,halfFields=[10,.1,'world half-width',10],
    runtimeFadeVector=dict(configurationField='0x98',namedValues=dict(zip(('gAlphaFadeRange','gAlphaFadeRadius','gAlphaFadeRangeFar','gAlphaFadeRadiusFar'),fade))),
    widthMeaning='Half-width in ly; original quad corner.w is -1 or +1',sourceTexture=texture['name'],sourceFormat=107,
    nativeFormat=98,format='BC7_UNorm',width=512,height=512,mipCount=10,mips=texture['mipLayout'],
    payloadBytes=len(payload),payloadSha256=hashlib.sha256(payload).hexdigest(),gameProcessAccess=False,gameCalls=0,
    fullOriginalGridRestored=False)
effects=root/'effects';effect_metadata=json.loads((effects/'original-effects.json').read_text())
archive=next(a for a in effect_metadata['archives'] if a['name']=='Effects_Win64_SM50.arc')
raw_effect=(effects/(archive['name']+'.raw')).read_bytes()
if hashlib.sha256(raw_effect).hexdigest()!=archive['inflatedSha256']:raise ValueError('Original effects archive changed')
result['shaders']=[shader for shader in archive['selected'] if '_StarMapLine_' in shader['name']]
for shader in result['shaders']:
    if hashlib.sha256((effects/(shader['name']+'.dxbc')).read_bytes()).hexdigest()!=shader['sha256']:raise ValueError('Original line shader changed')
# The effect archive retains a frozen named-descriptor block even though the
# actual DXBC has no RDEF chunk. Preserve the descriptors rather than treating
# string-table order alone as the final GPU scalar-offset proof.
reflection_base=0xfe08c0
if struct.unpack_from('<QQ',raw_effect,reflection_base+0x48)!=(0x18e0,489):raise ValueError('Original StarMapLine reflection layout changed')
descriptors=[]
for index in range(489):
    location=reflection_base+0x18e0+index*32;pointer=reflection_base+struct.unpack_from('<Q',raw_effect,location)[0]
    name=raw_effect[pointer:raw_effect.find(b'\0',pointer)].decode('ascii')
    if name.startswith('gAlphaFade'):
        descriptors.append(dict(name=name,index=index,archiveOffset=location,raw=raw_effect[location:location+32].hex()))
if [d['name'] for d in descriptors]!=['gAlphaFadeRadius','gAlphaFadeRadiusFar','gAlphaFadeRange','gAlphaFadeRangeFar']:
    raise ValueError('Original local fade descriptors changed')
result['effectLocalFadeDescriptors']=descriptors
quad=[list(struct.unpack('<4f',original_bytes(rva,16))) for rva in (0x54c7d80,0x54c7d70,0x54c7d60,0x54c7d60,0x50bd330,0x54c7d80)]
if quad!=[[0,1,-1,-1],[0,0,-1,1],[1,0,1,1],[1,0,1,1],[1,1,1,-1],[0,1,-1,-1]]:raise ValueError('Original generic quad changed')
result['geometry']=dict(vertices=quad,endpointSelectors=[1,1,2,2,2,1],recordBytes=64,layout=dict(fromXyz=0,toXyz=12,half4=24,rgba=32,uv=48),
    lineObject='renderer.viewport[viewportIndex]+0x40',writerRva='0x3c11750',constructorChain=['0x39fac80','0x3c01470','0x3c10980'])
paths=[root/'decompiled/solo-3a1ede0.c',root/'decompiled/solo-3a441a0.c',root/'decompiled/solo-3ab44e0.c',
    root/'material-slots/solo-3a5bd80.c',*[root/('grid/solo-'+rva+'.c') for rva in ('3c11750','39fac80','3a09210','3c01470')]]
result['decompiledSourceEvidence']=[dict(path=str(path).replace('\\','/'),sha256=hashlib.sha256(path.read_bytes()).hexdigest()) for path in paths]
result['remainingLimits']=['Original shared RGB multiplier and final HDR output','Sampler quality selection',
    'Original final projection/FOV integration','Final GPU scalar-offset binding interpretation remains distinct from named publisher registration']
(out/'original-grid-line.json').write_text(json.dumps(result,indent=2)+'\n',encoding='utf-8')
# This is an inspection artifact, not a substitute generated texture.
dds=(b'DDS '+struct.pack('<7I',124,0x81007,512,512,262144,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)+payload[:262144])
decoded=Image.open(io.BytesIO(dds)).convert('RGBA');decoded.save(root/'grid/original-line-texture.png')
decoded.getchannel('A').save(root/'grid/original-line-alpha.png')
print(json.dumps(dict(payloadSha256=result['payloadSha256'],payloadBytes=len(payload),compressedBytes=(out/'original-grid-line.bc7.gz').stat().st_size)))