"""Export the original authored Galaxy plane and its exact packed transform.
The model's source affine transform passes through4350170. Its normalized
quaternion is packed with32767 (not32767.5), proven by the leaf CRT initializer.
"""
from pathlib import Path
import gzip,hashlib,json,struct
import pefile
root=Path('artifacts/galaxy-query-research/power-outer-sources')
models=json.loads((root/'authored-models/original-authored-models.json').read_text())
model=next(m for m in models['models'] if m['name']=='milkywayplane_')
scope={};exec(Path('research/Extract-GalaxyRenderMaterials.py').read_text().split('for group,entry in enumerate(buffers):')[0],scope)
materials=json.loads((root/'material/original-materials.json').read_text())
texture=next(t for t in materials['textures'] if t['name']=='milkywayplane.pdiffuse_alphatexture')
if (texture['sourceFormat'],texture['width'],texture['height'],texture['mips'],texture['gpuBytes'])!=(108,2048,2048,12,5596160):
raise ValueError('Original plane texture changed')
image=Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe')
raw=image.read_bytes()
if hashlib.sha256(raw).hexdigest()!=models['gameImageSha256']:raise ValueError('Pinned model image changed')
pe=pefile.PE(data=raw,fast_load=True)
if pe.get_data(0x14FFF0,20).hex()!='f30f100d682c92050fc6c9000f290ded4bf005c3':
raise ValueError('Original quaternion scale initializer changed')
if struct.unpack('<f',pe.get_data(0x5A72C60,4))[0]!=32767 or struct.unpack('<I',pe.get_data(0x4E2E500+108*4,4))[0]!=99:
raise ValueError('Original quaternion/texture format constants changed')
if struct.unpack('<Q',pe.get_data(0x4DDE7C0,8))[0]!=pe.OPTIONAL_HEADER.ImageBase+0x14FFF0:
raise ValueError('Original quaternion scale CRT binding changed')
mesh=Path(model['gpuPath']).read_bytes()
if hashlib.sha256(mesh).hexdigest()!=model['gpuSha256']:raise ValueError('Original plane packed mesh changed')
links=json.loads((root/'authored-models/effects/original-effect-shader-links.json').read_text())
effect=next(e for e in links['effects'] if e['effect']=='Alpha_UnlitNoScale_StarMapFacingAlpha_NearFade_Forward')
vertex_blob=(root/'authored-models/effects'/ (effect['shaders'][0]['name']+'.dxbc')).read_bytes()
if vertex_blob.count(struct.pack('<f',1/32767))!=6 or vertex_blob.count(struct.pack('<f',2/65535))!=3:
raise ValueError('Original UV/quaternion shader coefficients changed')
parameters={p['name']:p['floatValues'] if 'floatValues' in p else p['integerValue'] for p in model['material']['parameters']}
payload=scope['b'][texture['gpuOffset']:texture['gpuOffset']+texture['gpuBytes']]
out=Path('XFEEDToolBox.Core/Rendering')
(out/'original-galaxy-plane-mesh.bin.gz').write_bytes(gzip.compress(mesh,mtime=0))
(out/'original-galaxy-plane-texture.bc7.gz').write_bytes(gzip.compress(payload,mtime=0))
result=dict(gameImageSha256=models['gameImageSha256'],resource=models['resource'],archiveSha256=models['archiveSha256'],
frozenSha256=models['frozenSha256'],gameProcessAccess=False,gameCalls=0,mesh=model,
texture=dict(width=2048,height=2048,mips=texture['mipLayout'],sourceFormat=108,dxgiFormat=99,
payloadBytes=len(payload),payloadSha256=hashlib.sha256(payload).hexdigest()),
actualShaderBinding=effect,parameters=parameters,
sourceFunctions=[dict(path=str(path),sha256=hashlib.sha256(path.read_bytes()).hexdigest()) for path in [
root/'background/model-vertex/solo-4350170.c',root/'background/model-vertex/solo-4c84400.c',
root/'background/solo-3b067d0.c',root/'background/solo-3a5baf0.c']],
packedInstance=dict(stride=336,skinPaletteBase=0,scale=100000,absolutePosition=[50000,40955,50000],
normalizedQuaternion=[0,1,0,0],packingScale=32767,quaternionU16=[32767,65534,32767,32767],
producer='0x4350170',submit='0x434FE20',initializer='0x4C861B0',
packingScaleInitializer='0x14FFF0',packingScaleSource='0x5A72C60',crtBinding='0x4DDE7C0',
gpuDecodeReciprocal=1/32767,gpuDecodeReciprocalBits='0x38000100',
vertexInputBuilder='0x4C84400',inputStride=40,attributeOffsets=dict(packedVertexDataA=0,packedVertexDataB=16,packedVertexDataC=32)),
fullRestored=False,unclosed=['runtime material overrides','complete Galaxy source layer/HDR ordering'])
(out/'original-galaxy-plane.json').write_text(json.dumps(result,indent=2)+'\n',encoding='utf-8')
print(json.dumps(dict(meshBytes=len(mesh),meshSha256=hashlib.sha256(mesh).hexdigest(),textureBytes=len(payload),textureSha256=hashlib.sha256(payload).hexdigest())))
"""Export the original authored Galaxy plane and its exact packed transform.
The model's source affine transform passes through4350170. Its normalized
quaternion is packed with32767 (not32767.5), proven by the leaf CRT initializer.
"""
from pathlib import Path
import gzip,hashlib,json,struct
import pefile
root=Path('artifacts/galaxy-query-research/power-outer-sources')
models=json.loads((root/'authored-models/original-authored-models.json').read_text())
model=next(m for m in models['models'] if m['name']=='milkywayplane_')
scope={};exec(Path('research/Extract-GalaxyRenderMaterials.py').read_text().split('for group,entry in enumerate(buffers):')[0],scope)
materials=json.loads((root/'material/original-materials.json').read_text())
texture=next(t for t in materials['textures'] if t['name']=='milkywayplane.pdiffuse_alphatexture')
if (texture['sourceFormat'],texture['width'],texture['height'],texture['mips'],texture['gpuBytes'])!=(108,2048,2048,12,5596160):
raise ValueError('Original plane texture changed')
image=Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe')
raw=image.read_bytes()
if hashlib.sha256(raw).hexdigest()!=models['gameImageSha256']:raise ValueError('Pinned model image changed')
pe=pefile.PE(data=raw,fast_load=True)
if pe.get_data(0x14FFF0,20).hex()!='f30f100d682c92050fc6c9000f290ded4bf005c3':
raise ValueError('Original quaternion scale initializer changed')
if struct.unpack('<f',pe.get_data(0x5A72C60,4))[0]!=32767 or struct.unpack('<I',pe.get_data(0x4E2E500+108*4,4))[0]!=99:
raise ValueError('Original quaternion/texture format constants changed')
if struct.unpack('<Q',pe.get_data(0x4DDE7C0,8))[0]!=pe.OPTIONAL_HEADER.ImageBase+0x14FFF0:
raise ValueError('Original quaternion scale CRT binding changed')
mesh=Path(model['gpuPath']).read_bytes()
if hashlib.sha256(mesh).hexdigest()!=model['gpuSha256']:raise ValueError('Original plane packed mesh changed')
links=json.loads((root/'authored-models/effects/original-effect-shader-links.json').read_text())
effect=next(e for e in links['effects'] if e['effect']=='Alpha_UnlitNoScale_StarMapFacingAlpha_NearFade_Forward')
vertex_blob=(root/'authored-models/effects'/ (effect['shaders'][0]['name']+'.dxbc')).read_bytes()
if vertex_blob.count(struct.pack('<f',1/32767))!=6 or vertex_blob.count(struct.pack('<f',2/65535))!=3:
raise ValueError('Original UV/quaternion shader coefficients changed')
parameters={p['name']:p['floatValues'] if 'floatValues' in p else p['integerValue'] for p in model['material']['parameters']}
payload=scope['b'][texture['gpuOffset']:texture['gpuOffset']+texture['gpuBytes']]
out=Path('XFEEDToolBox.Core/Rendering')
(out/'original-galaxy-plane-mesh.bin.gz').write_bytes(gzip.compress(mesh,mtime=0))
(out/'original-galaxy-plane-texture.bc7.gz').write_bytes(gzip.compress(payload,mtime=0))
result=dict(gameImageSha256=models['gameImageSha256'],resource=models['resource'],archiveSha256=models['archiveSha256'],
frozenSha256=models['frozenSha256'],gameProcessAccess=False,gameCalls=0,mesh=model,
texture=dict(width=2048,height=2048,mips=texture['mipLayout'],sourceFormat=108,dxgiFormat=99,
payloadBytes=len(payload),payloadSha256=hashlib.sha256(payload).hexdigest()),
actualShaderBinding=effect,parameters=parameters,
sourceFunctions=[dict(path=str(path),sha256=hashlib.sha256(path.read_bytes()).hexdigest()) for path in [
root/'background/model-vertex/solo-4350170.c',root/'background/model-vertex/solo-4c84400.c',
root/'background/solo-3b067d0.c',root/'background/solo-3a5baf0.c']],
packedInstance=dict(stride=336,skinPaletteBase=0,scale=100000,absolutePosition=[50000,40955,50000],
normalizedQuaternion=[0,1,0,0],packingScale=32767,quaternionU16=[32767,65534,32767,32767],
producer='0x4350170',submit='0x434FE20',initializer='0x4C861B0',
packingScaleInitializer='0x14FFF0',packingScaleSource='0x5A72C60',crtBinding='0x4DDE7C0',
gpuDecodeReciprocal=1/32767,gpuDecodeReciprocalBits='0x38000100',
vertexInputBuilder='0x4C84400',inputStride=40,attributeOffsets=dict(packedVertexDataA=0,packedVertexDataB=16,packedVertexDataC=32)),
fullRestored=False,unclosed=['runtime material overrides','complete Galaxy source layer/HDR ordering'])
(out/'original-galaxy-plane.json').write_text(json.dumps(result,indent=2)+'\n',encoding='utf-8')
print(json.dumps(dict(meshBytes=len(mesh),meshSha256=hashlib.sha256(mesh).hexdigest(),textureBytes=len(payload),textureSha256=hashlib.sha256(payload).hexdigest())))