"""Pin original shared HDR variable descriptors and their GPU-slot cross-check.
Variable data offsets are retained separately from GPU register offsets. The
CameraPos anchor independently connects this shader's shared buffer to the PS.
"""
from pathlib import Path
import hashlib,json,re,struct
import pefile
path=Path('artifacts/galaxy-query-research/power-outer-sources/effects/Effects_Win64_SM50.arc.raw')
b=path.read_bytes()
if hashlib.sha256(b).hexdigest()!='649e3107c868fe31ba23c9e1d19be2b99777b908431987f04f08cd39f0f798ca':raise ValueError('Pinned effects changed')
effect=0x58CB78
if b[effect:effect+8]!=b'\x08\x02xfxd3f':raise ValueError('Original GalaxyGlow effect changed')
magic=b.find(b'\x00\x01voMrtP',effect+32);size,count=struct.unpack_from('<II',b,magic+8);start=magic+16
d=b[start:start+size];pointer,variables=struct.unpack_from('<2Q',d,0x48)
if (size,count,pointer,variables)!=(36400,523,6672,518):raise ValueError('Original frozen reflection changed')
rows={}
for i in range(variables):
offset=pointer+i*32;name_ptr=struct.unpack_from('<Q',d,offset)[0];end=d.index(b'\0',name_ptr)
name=d[name_ptr:end].decode('ascii');raw=d[offset:offset+32]
if name in {'gHDRScalingWrite','gHDRScalingRead','gCameraPos','gCameraUp','gCameraRight','gExposureCompensation','gEmissiveMultiplier','gHDRParams'}:
# Descriptor high offset bits, preserving the original packed word.
packed=struct.unpack_from('<I',raw,8)[0];data_offset=(packed>>17)&~3
rows[name]=dict(index=i,archiveOffset=start+offset,raw=raw.hex(),packedWord=hex(packed),variableDataOffset=data_offset)
anchor=rows['gCameraPos']['variableDataOffset']-275*16
if anchor!=272 or rows['gHDRScalingWrite']['variableDataOffset']-anchor!=90*16+4 or rows['gHDRScalingRead']['variableDataOffset']-anchor!=90*16+8:
raise ValueError('Shared HDR/CameraPos GPU-slot cross-check failed')
first=b[effect+32:effect+32+0x3F0]
if first[0x3C0:0x3D0]!=bytes.fromhex('c2000000000000002604010000040000'):raise ValueError('Shared constant-buffer descriptor changed')
out=Path('artifacts/galaxy-query-research/power-outer-sources/background/shared-hdr-reflection.json')
result=dict(gameProcessAccess=False,gameCalls=0,source=str(path),sourceSha256=hashlib.sha256(b).hexdigest(),
effect='GalaxyGlow',effectOffset=effect,reflectionObjectOffset=start,variables=rows,
anchor=dict(name='gCameraPos',actualPixelShaderRegister='cb1[275].xyz',dataOffset=4672,sharedDataOffset=anchor),
sharedBufferDescriptor=dict(name='__shared_f3d_globals',archiveOffset=effect+32+0x3C0,raw=first[0x3C0:0x3D0].hex()),
gpuSlotCrossCheck={'cb1[90].y':'gHDRScalingWrite','cb1[90].z':'gHDRScalingRead'},
outstanding=['native shared-buffer range descriptor interpretation','actual runtime Write/Read values and update source',
'selected final HDR/tonemapping pass and its parameters'],fullOutputRestored=False)
image=Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe')
image_bytes=image.read_bytes();image_sha=hashlib.sha256(image_bytes).hexdigest()
if image_sha!='6891f70a021fa9f3a0e00458c284f48d1226e68ae7fc02ad48081aed47857e93':raise ValueError('Pinned HDR image changed')
pe=pefile.PE(data=image_bytes,fast_load=True);image_base=pe.OPTIONAL_HEADER.ImageBase
defaults=[]
for rva,field,value,hex_bytes in [(0x27FC0B8,0xA0C,1/256,'c7830c0a00000000803b'),(0x27FC0C2,0xA10,256,'c783100a000000008043'),
(0x27FC0CC,0xA14,1/256,'c783140a00000000803b'),(0x27FC0D6,0xA18,256,'c783180a000000008043')]:
raw=pe.get_data(rva,len(bytes.fromhex(hex_bytes)))
if raw.hex()!=hex_bytes or struct.unpack('<f',raw[-4:])[0]!=value:raise ValueError('Original HDR default constructor changed')
defaults.append(dict(rva=hex(rva),frameDataField=hex(field),value=value,bytes=raw.hex()))
if struct.unpack('<Q',pe.get_data(0x52F1AB0+0x10,8))[0]!=image_base+0x28783B0:raise ValueError('HDR publishing vtable changed')
source_functions=[]
for name in ['27f6eb0','27fbe00','287b5e0','284e020']:
source_path=out.parent/('solo-'+name+'.c')
if source_path.exists():source_functions.append(dict(rva='0x'+name,path=str(source_path),sha256=hashlib.sha256(source_path.read_bytes()).hexdigest()))
result['nativeBinding']=dict(gameImageSha256=image_sha,constructor='0x27F6EB0',vtable='0x52F1AB0',
publishSlot='0x10',publishFunction='0x28783B0',sharedFrameGetter='0x28ABB40: *(context+10)+2CC0',
fields=dict(normalWrite='view+36CC',normalRead='view+36D0',mode3Write='view+36D4',mode3Read='view+36D8'),
defaultConstructor='0x27FBE00',defaults=defaults,sourceFunctions=source_functions,
liveValuesNotRead=True)
out.write_text(json.dumps(result,indent=2)+'\n',encoding='utf-8');print(json.dumps(dict(path=str(out),sharedDataOffset=anchor,slots=result['gpuSlotCrossCheck'])))
"""Pin original shared HDR variable descriptors and their GPU-slot cross-check.
Variable data offsets are retained separately from GPU register offsets. The
CameraPos anchor independently connects this shader's shared buffer to the PS.
"""
from pathlib import Path
import hashlib,json,re,struct
import pefile
path=Path('artifacts/galaxy-query-research/power-outer-sources/effects/Effects_Win64_SM50.arc.raw')
b=path.read_bytes()
if hashlib.sha256(b).hexdigest()!='649e3107c868fe31ba23c9e1d19be2b99777b908431987f04f08cd39f0f798ca':raise ValueError('Pinned effects changed')
effect=0x58CB78
if b[effect:effect+8]!=b'\x08\x02xfxd3f':raise ValueError('Original GalaxyGlow effect changed')
magic=b.find(b'\x00\x01voMrtP',effect+32);size,count=struct.unpack_from('<II',b,magic+8);start=magic+16
d=b[start:start+size];pointer,variables=struct.unpack_from('<2Q',d,0x48)
if (size,count,pointer,variables)!=(36400,523,6672,518):raise ValueError('Original frozen reflection changed')
rows={}
for i in range(variables):
offset=pointer+i*32;name_ptr=struct.unpack_from('<Q',d,offset)[0];end=d.index(b'\0',name_ptr)
name=d[name_ptr:end].decode('ascii');raw=d[offset:offset+32]
if name in {'gHDRScalingWrite','gHDRScalingRead','gCameraPos','gCameraUp','gCameraRight','gExposureCompensation','gEmissiveMultiplier','gHDRParams'}:
# Descriptor high offset bits, preserving the original packed word.
packed=struct.unpack_from('<I',raw,8)[0];data_offset=(packed>>17)&~3
rows[name]=dict(index=i,archiveOffset=start+offset,raw=raw.hex(),packedWord=hex(packed),variableDataOffset=data_offset)
anchor=rows['gCameraPos']['variableDataOffset']-275*16
if anchor!=272 or rows['gHDRScalingWrite']['variableDataOffset']-anchor!=90*16+4 or rows['gHDRScalingRead']['variableDataOffset']-anchor!=90*16+8:
raise ValueError('Shared HDR/CameraPos GPU-slot cross-check failed')
first=b[effect+32:effect+32+0x3F0]
if first[0x3C0:0x3D0]!=bytes.fromhex('c2000000000000002604010000040000'):raise ValueError('Shared constant-buffer descriptor changed')
out=Path('artifacts/galaxy-query-research/power-outer-sources/background/shared-hdr-reflection.json')
result=dict(gameProcessAccess=False,gameCalls=0,source=str(path),sourceSha256=hashlib.sha256(b).hexdigest(),
effect='GalaxyGlow',effectOffset=effect,reflectionObjectOffset=start,variables=rows,
anchor=dict(name='gCameraPos',actualPixelShaderRegister='cb1[275].xyz',dataOffset=4672,sharedDataOffset=anchor),
sharedBufferDescriptor=dict(name='__shared_f3d_globals',archiveOffset=effect+32+0x3C0,raw=first[0x3C0:0x3D0].hex()),
gpuSlotCrossCheck={'cb1[90].y':'gHDRScalingWrite','cb1[90].z':'gHDRScalingRead'},
outstanding=['native shared-buffer range descriptor interpretation','actual runtime Write/Read values and update source',
'selected final HDR/tonemapping pass and its parameters'],fullOutputRestored=False)
image=Path('artifacts/ship-model-reference/client-copy/EliteDangerous64.exe')
image_bytes=image.read_bytes();image_sha=hashlib.sha256(image_bytes).hexdigest()
if image_sha!='6891f70a021fa9f3a0e00458c284f48d1226e68ae7fc02ad48081aed47857e93':raise ValueError('Pinned HDR image changed')
pe=pefile.PE(data=image_bytes,fast_load=True);image_base=pe.OPTIONAL_HEADER.ImageBase
defaults=[]
for rva,field,value,hex_bytes in [(0x27FC0B8,0xA0C,1/256,'c7830c0a00000000803b'),(0x27FC0C2,0xA10,256,'c783100a000000008043'),
(0x27FC0CC,0xA14,1/256,'c783140a00000000803b'),(0x27FC0D6,0xA18,256,'c783180a000000008043')]:
raw=pe.get_data(rva,len(bytes.fromhex(hex_bytes)))
if raw.hex()!=hex_bytes or struct.unpack('<f',raw[-4:])[0]!=value:raise ValueError('Original HDR default constructor changed')
defaults.append(dict(rva=hex(rva),frameDataField=hex(field),value=value,bytes=raw.hex()))
if struct.unpack('<Q',pe.get_data(0x52F1AB0+0x10,8))[0]!=image_base+0x28783B0:raise ValueError('HDR publishing vtable changed')
source_functions=[]
for name in ['27f6eb0','27fbe00','287b5e0','284e020']:
source_path=out.parent/('solo-'+name+'.c')
if source_path.exists():source_functions.append(dict(rva='0x'+name,path=str(source_path),sha256=hashlib.sha256(source_path.read_bytes()).hexdigest()))
result['nativeBinding']=dict(gameImageSha256=image_sha,constructor='0x27F6EB0',vtable='0x52F1AB0',
publishSlot='0x10',publishFunction='0x28783B0',sharedFrameGetter='0x28ABB40: *(context+10)+2CC0',
fields=dict(normalWrite='view+36CC',normalRead='view+36D0',mode3Write='view+36D4',mode3Read='view+36D8'),
defaultConstructor='0x27FBE00',defaults=defaults,sourceFunctions=source_functions,
liveValuesNotRead=True)
out.write_text(json.dumps(result,indent=2)+'\n',encoding='utf-8');print(json.dumps(dict(path=str(out),sharedDataOffset=anchor,slots=result['gpuSlotCrossCheck'])))