"""Copy the actual BlackHoles texture and bind existing offline producer/state evidence."""
import gzip,hashlib,json,struct
from pathlib import Path
import pefile
from capstone import Cs,CS_ARCH_X86,CS_MODE_64
from capstone.x86_const import X86_OP_MEM,X86_OP_IMM
folder=Path('artifacts/galaxy-query-research/power-outer-sources')
meta=json.loads((folder/'material/original-materials.json').read_text())
body=(folder/'material'/(meta['resource']+'.stream0')).read_bytes()
assert hashlib.sha256(body).hexdigest()==meta['frozenSha256']
texture=next(t for t in meta['textures'] if t['name']=='blackholes.pdiffusetexture')
assert (texture['width'],texture['height'],texture['array'],texture['mips'],texture['gpuBytes'])==(512,512,1,10,181248)
payload=body[texture['gpuOffset']:texture['gpuOffset']+texture['gpuBytes']]
material=next(m for m in meta['materials'] if m['name']=='blackholes')
blend=next(m for m in json.loads((folder/'material-slots/original-blend-application.json').read_text())['materials'] if m['material']=='blackholes')
assert blend['resolved'] and blend['d3d11']==dict(rgbSource=5,rgbDestination=8,rgbOperation=1,alphaSource=5,alphaDestination=8,alphaOperation=1)
image=Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe').read_bytes()
assert hashlib.sha256(image).hexdigest()=='6891f70a021fa9f3a0e00458c284f48d1226e68ae7fc02ad48081aed47857e93'
pe=pefile.PE(data=image,fast_load=True)
rgba=struct.unpack('<4f',pe.get_data(0x4DEF770,16));assert rgba==(1,1,1,1)
assert pe.get_data(0x551F150,10).split(b'\0')[0]==b'pSrcBlend'
assert pe.get_data(0x551F160,11).split(b'\0')[0]==b'pDestBlend'
decoder=Cs(CS_ARCH_X86,CS_MODE_64);decoder.detail=True
pe.parse_data_directories(directories=[3]);entry=next(e.struct for e in pe.DIRECTORY_ENTRY_EXCEPTION if e.struct.BeginAddress==0x3A09F20)
instructions=list(decoder.disasm(pe.get_data(entry.BeginAddress,entry.EndAddress-entry.BeginAddress),entry.BeginAddress))
stores=[]
for offset,value in [(0x1178,4),(0x1208,1)]:
matches=[i for i in instructions if i.mnemonic=='mov' and len(i.operands)==2 and i.operands[0].type==X86_OP_MEM
and i.operands[0].mem.disp==offset and i.operands[1].type==X86_OP_IMM and i.operands[1].imm==value]
assert len(matches)==1
i=matches[0];stores.append(dict(offset=hex(offset),value=value,rva=hex(i.address),raw=i.bytes.hex()))
publisher=(folder.parent/'constellations/decompiled/solo-3aac040.c').read_text()
assert 'param_1 + 0x10f0' in publisher and 'param_1 + 0x1180' in publisher
factory=(folder.parent/'constellations/decompiled/solo-39f2210.c').read_text();assert 'FUN_143a09f20(lVar1,param_3)' in factory
creator=(folder/'decompiled/solo-3a5bd80.c').read_text()
assert 'unaff_RDI + 0x8c8' in creator and '+ 0xe8)' in creator
# Replay the same real effect program after the actual named publisher defaults,
# rather than pretending authored FGM pDestBlend7 survives its runtime override.
scope={};exec(Path('research/Trace-OriginalGalaxyBlendApplication.py').read_text().split('materials = json.loads')[0],scope)
effect=next(e for e in scope['effects'] if 'BackgroundBlackHole_Forward0' in e['passes'])
runtime_material={**material,'parameters':[dict(p,raw='01000000') if p['name']=='pDestBlend' else p for p in material['parameters']]}
runtime_blend=scope['replay'](effect,effect['blendStates'][0],runtime_material)
assert runtime_blend['d3d11']==dict(rgbSource=5,rgbDestination=2,rgbOperation=1,alphaSource=5,alphaDestination=2,alphaOperation=1)
assert pe.get_data(0x5521A90,28).split(b'\0')[0]==b'GM_DisplayOptions_Navigation'
assert struct.unpack('<Q',pe.get_data(0x551FEC8+0xD0,8))[0]-pe.OPTIONAL_HEADER.ImageBase==0x3A4DFA0
assert pe.get_data(0x3A4DFA0,30).hex()=='4883ec28488b89e8010000488b01ff90f001000085c00f95c04883c428c3'
config=json.loads((folder/'material-slots/material-property-slots.json').read_text())
glow=config['runtimeVectors']['0x180'];assert glow==[2.75,0.17000000178813934,1.902999997138977]
refs=json.loads((folder/'render-config-refs.json').read_text());assert next(r for r in refs if r['field']=='0xe8')['text']=='BlackHoles'
producer=(folder/'decompiled/solo-3a431c0.c').read_text()
assert "else if (param_7 != '\\0')" in producer and 'fStack_e0 = 0.0;' in producer and '_UNK_144def770' in producer
runtime=(folder/'decompiled/solo-3ab44e0.c').read_text()
assert 'auStack_48[4] = *(undefined8 *)(param_1 + 0x8c8);' in runtime and '*(undefined8 *)(param_1 + 0x938)' in runtime
shader={}
for stage in ['vs','ps']:
file=folder/'effects'/f'{stage}_BackgroundBlackHole_Forward0_0_Win64_SM50.dxbc'
shader[stage]=dict(path=str(file),bytes=file.stat().st_size,sha256=hashlib.sha256(file.read_bytes()).hexdigest())
out=Path('XFEEDToolBox.Core/Rendering')
with (out/'original-black-hole.bc1.gz').open('wb') as f:
with gzip.GzipFile(filename='',mode='wb',fileobj=f,mtime=0,compresslevel=9) as z:z.write(payload)
result=dict(sourceResource=meta['resource'],sourceArchiveSha256=meta['sourceArchiveSha256'],frozenSha256=meta['frozenSha256'],
sourceTexture=texture['name'],format='BC1_UNorm',width=512,height=512,layers=1,mipCount=10,mips=texture['mipLayout'],
payloadBytes=len(payload),payloadSha256=hashlib.sha256(payload).hexdigest(),shader=shader,
sourceImageSha256=hashlib.sha256(image).hexdigest(),specialTypes=[41,42],producer='0x3A431C0',
size='IEEE half(original styleSize), no pixel minimum',layer=0,instanceRgba=rgba,colourGamma=1,
internalGlow=glow,alternateInternalGlow=config['runtimeVectors']['0x188'],authoredBlend=blend['d3d11'],blend=runtime_blend['d3d11'],
runtimeBlend=runtime_blend,namedPublisherDefaults=stores,
navigationGate=dict(param=7,source='Main registered5FDB224/vfuncD0(5) ->Settings1F0(5)!=0',getter='0x3A4DFA0',label='GM_DisplayOptions_Navigation',toolProperty='ShowRoute'),
sourceBlendProgram=blend['programRaw'],runtimePublisher='renderer8C8/938 -> configE8 BlackHoles; runtime3AB44E0',
gameProcessAccess=False,gameCalls=0,fullSceneRestored=False,
limits=['Original runtime alternate-glow selector remains separately unavailable.',
'Actual publisher defaults override the authored destination-alpha blend. Final game scene order is not inferred.'])
(out/'original-black-hole.json').write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps(dict(payloadBytes=len(payload),compressedBytes=(out/'original-black-hole.bc1.gz').stat().st_size,payloadSha256=result['payloadSha256'],shader=shader),indent=2))
"""Copy the actual BlackHoles texture and bind existing offline producer/state evidence."""
import gzip,hashlib,json,struct
from pathlib import Path
import pefile
from capstone import Cs,CS_ARCH_X86,CS_MODE_64
from capstone.x86_const import X86_OP_MEM,X86_OP_IMM
folder=Path('artifacts/galaxy-query-research/power-outer-sources')
meta=json.loads((folder/'material/original-materials.json').read_text())
body=(folder/'material'/(meta['resource']+'.stream0')).read_bytes()
assert hashlib.sha256(body).hexdigest()==meta['frozenSha256']
texture=next(t for t in meta['textures'] if t['name']=='blackholes.pdiffusetexture')
assert (texture['width'],texture['height'],texture['array'],texture['mips'],texture['gpuBytes'])==(512,512,1,10,181248)
payload=body[texture['gpuOffset']:texture['gpuOffset']+texture['gpuBytes']]
material=next(m for m in meta['materials'] if m['name']=='blackholes')
blend=next(m for m in json.loads((folder/'material-slots/original-blend-application.json').read_text())['materials'] if m['material']=='blackholes')
assert blend['resolved'] and blend['d3d11']==dict(rgbSource=5,rgbDestination=8,rgbOperation=1,alphaSource=5,alphaDestination=8,alphaOperation=1)
image=Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe').read_bytes()
assert hashlib.sha256(image).hexdigest()=='6891f70a021fa9f3a0e00458c284f48d1226e68ae7fc02ad48081aed47857e93'
pe=pefile.PE(data=image,fast_load=True)
rgba=struct.unpack('<4f',pe.get_data(0x4DEF770,16));assert rgba==(1,1,1,1)
assert pe.get_data(0x551F150,10).split(b'\0')[0]==b'pSrcBlend'
assert pe.get_data(0x551F160,11).split(b'\0')[0]==b'pDestBlend'
decoder=Cs(CS_ARCH_X86,CS_MODE_64);decoder.detail=True
pe.parse_data_directories(directories=[3]);entry=next(e.struct for e in pe.DIRECTORY_ENTRY_EXCEPTION if e.struct.BeginAddress==0x3A09F20)
instructions=list(decoder.disasm(pe.get_data(entry.BeginAddress,entry.EndAddress-entry.BeginAddress),entry.BeginAddress))
stores=[]
for offset,value in [(0x1178,4),(0x1208,1)]:
matches=[i for i in instructions if i.mnemonic=='mov' and len(i.operands)==2 and i.operands[0].type==X86_OP_MEM
and i.operands[0].mem.disp==offset and i.operands[1].type==X86_OP_IMM and i.operands[1].imm==value]
assert len(matches)==1
i=matches[0];stores.append(dict(offset=hex(offset),value=value,rva=hex(i.address),raw=i.bytes.hex()))
publisher=(folder.parent/'constellations/decompiled/solo-3aac040.c').read_text()
assert 'param_1 + 0x10f0' in publisher and 'param_1 + 0x1180' in publisher
factory=(folder.parent/'constellations/decompiled/solo-39f2210.c').read_text();assert 'FUN_143a09f20(lVar1,param_3)' in factory
creator=(folder/'decompiled/solo-3a5bd80.c').read_text()
assert 'unaff_RDI + 0x8c8' in creator and '+ 0xe8)' in creator
# Replay the same real effect program after the actual named publisher defaults,
# rather than pretending authored FGM pDestBlend7 survives its runtime override.
scope={};exec(Path('research/Trace-OriginalGalaxyBlendApplication.py').read_text().split('materials = json.loads')[0],scope)
effect=next(e for e in scope['effects'] if 'BackgroundBlackHole_Forward0' in e['passes'])
runtime_material={**material,'parameters':[dict(p,raw='01000000') if p['name']=='pDestBlend' else p for p in material['parameters']]}
runtime_blend=scope['replay'](effect,effect['blendStates'][0],runtime_material)
assert runtime_blend['d3d11']==dict(rgbSource=5,rgbDestination=2,rgbOperation=1,alphaSource=5,alphaDestination=2,alphaOperation=1)
assert pe.get_data(0x5521A90,28).split(b'\0')[0]==b'GM_DisplayOptions_Navigation'
assert struct.unpack('<Q',pe.get_data(0x551FEC8+0xD0,8))[0]-pe.OPTIONAL_HEADER.ImageBase==0x3A4DFA0
assert pe.get_data(0x3A4DFA0,30).hex()=='4883ec28488b89e8010000488b01ff90f001000085c00f95c04883c428c3'
config=json.loads((folder/'material-slots/material-property-slots.json').read_text())
glow=config['runtimeVectors']['0x180'];assert glow==[2.75,0.17000000178813934,1.902999997138977]
refs=json.loads((folder/'render-config-refs.json').read_text());assert next(r for r in refs if r['field']=='0xe8')['text']=='BlackHoles'
producer=(folder/'decompiled/solo-3a431c0.c').read_text()
assert "else if (param_7 != '\\0')" in producer and 'fStack_e0 = 0.0;' in producer and '_UNK_144def770' in producer
runtime=(folder/'decompiled/solo-3ab44e0.c').read_text()
assert 'auStack_48[4] = *(undefined8 *)(param_1 + 0x8c8);' in runtime and '*(undefined8 *)(param_1 + 0x938)' in runtime
shader={}
for stage in ['vs','ps']:
file=folder/'effects'/f'{stage}_BackgroundBlackHole_Forward0_0_Win64_SM50.dxbc'
shader[stage]=dict(path=str(file),bytes=file.stat().st_size,sha256=hashlib.sha256(file.read_bytes()).hexdigest())
out=Path('XFEEDToolBox.Core/Rendering')
with (out/'original-black-hole.bc1.gz').open('wb') as f:
with gzip.GzipFile(filename='',mode='wb',fileobj=f,mtime=0,compresslevel=9) as z:z.write(payload)
result=dict(sourceResource=meta['resource'],sourceArchiveSha256=meta['sourceArchiveSha256'],frozenSha256=meta['frozenSha256'],
sourceTexture=texture['name'],format='BC1_UNorm',width=512,height=512,layers=1,mipCount=10,mips=texture['mipLayout'],
payloadBytes=len(payload),payloadSha256=hashlib.sha256(payload).hexdigest(),shader=shader,
sourceImageSha256=hashlib.sha256(image).hexdigest(),specialTypes=[41,42],producer='0x3A431C0',
size='IEEE half(original styleSize), no pixel minimum',layer=0,instanceRgba=rgba,colourGamma=1,
internalGlow=glow,alternateInternalGlow=config['runtimeVectors']['0x188'],authoredBlend=blend['d3d11'],blend=runtime_blend['d3d11'],
runtimeBlend=runtime_blend,namedPublisherDefaults=stores,
navigationGate=dict(param=7,source='Main registered5FDB224/vfuncD0(5) ->Settings1F0(5)!=0',getter='0x3A4DFA0',label='GM_DisplayOptions_Navigation',toolProperty='ShowRoute'),
sourceBlendProgram=blend['programRaw'],runtimePublisher='renderer8C8/938 -> configE8 BlackHoles; runtime3AB44E0',
gameProcessAccess=False,gameCalls=0,fullSceneRestored=False,
limits=['Original runtime alternate-glow selector remains separately unavailable.',
'Actual publisher defaults override the authored destination-alpha blend. Final game scene order is not inferred.'])
(out/'original-black-hole.json').write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps(dict(payloadBytes=len(payload),compressedBytes=(out/'original-black-hole.bc1.gz').stat().st_size,payloadSha256=result['payloadSha256'],shader=shader),indent=2))