'use strict';
const mod=Process.getModuleByName('EliteDangerous64.exe');
if(Process.id!==SNAPSHOT.pid || mod.path.toLowerCase()!==PROFILE.image.toLowerCase())throw Error('Selected game image changed');
const base=mod.base;
const component=name=>SNAPSHOT.components.find(x=>x.name===name);
const fsd=ptr(component('fsd').address),life=ptr(component('fsd').lifecycle);
const pose=ptr(SNAPSHOT.poseLookup.poseAddress);
const bodies=ptr(SNAPSHOT.fsdSources.find(x=>x.name==='spaceBodies').address);
const navigation=ptr(SNAPSHOT.fsdSources.find(x=>x.name==='navigationTarget').address);
const same=()=>Process.getCurrentThreadId()===THREAD&&life.add(0xC0).readU32()===8&&life.add(0xB0).readU64().toString()===SNAPSHOT.player.entityId&&fsd.add(0x6A0).readPointer().equals(bodies)&&fsd.add(0x320).readPointer().equals(pose);
const hex=(at,n)=>Array.from(new Uint8Array(at.readByteArray(n))).map(x=>x.toString(16).padStart(2,'0')).join('');
const method=(obj,off)=>obj.readPointer().add(off).readPointer();
const rva=p=>p.sub(base).toString();
if(!method(pose,0x60).equals(base.add(0x2D9C2C0))||!method(bodies,0x60).equals(base.add(0x3CEB400))||!method(bodies,0xD0).equals(base.add(0x3CF04B0))||!method(navigation,0xB8).equals(base.add(0x2EC8E20)))throw Error('Pinned original getter bindings changed');
const radiusOut=Memory.alloc(16);
const radiusGetter=new NativeFunction(base.add(0x3CF04B0),'pointer',['pointer','pointer','pointer']);
const targetGetter=new NativeFunction(base.add(0x2EC8E20),'pointer',['pointer']);
const finite=x=>Number.isFinite(x)&&Math.abs(x)<1e30;
let last=0,queries=0;
Interceptor.attach(base.add(0x3CEB400),{
onEnter(args){
this.selected=false;
try{
if(!args[0].equals(bodies)||!same())return;
queries++;
if(Date.now()-last<200)return;
this.out=args[1];this.address=args[2].readU64().toString();this.selected=true;
}catch(e){send({kind:'error',stage:'enter',error:String(e)});}
},
onLeave(ret){
if(!this.selected)return;
try{
if(!same())return;
const body=this.out.readPointer();if(body.isNull())return;
const kind=body.add(0x20).readU32();if(![1,2,7].includes(kind))return;
// The original caller still owns this returned body reference. Do not retain or release it.
const result=radiusGetter(bodies,radiusOut,body);if(!result.equals(radiusOut))throw Error('Radius getter returned an unexpected buffer');
const radius=radiusOut.readDouble(),settings=fsd.add(0x50).readPointer();
const multiplier=settings.add(0x44).readFloat();
if(!finite(radius)||radius<=0||!finite(multiplier)||multiplier<=0)throw Error('Invalid radius/settings');
const target=targetGetter(navigation);
const row={kind:'body-query',utcMilliseconds:Date.now(),thread:Process.getCurrentThreadId(),queries,queryUniversalAddress:this.address,
body:body.toString(),bodyKind:kind,bodyTableRva:rva(body.readPointer()),radius,escapeRadiusMultiplier:multiplier,
worldUniversalAddress:hex(pose.add(0xE8),160),worldAddress:pose.add(0xE8).readU64().toString(),
fsdStage:fsd.add(0x794).readU8(),selectedTarget:target.isNull()?null:hex(target,224),bodyHeader:hex(body,0x480)};
last=Date.now();send(row);
}catch(e){send({kind:'error',stage:'leave',error:String(e)});}
}
});
send({kind:'ready',pid:Process.id,thread:THREAD,readOnly:true,screenUse:false});
'use strict';
const mod=Process.getModuleByName('EliteDangerous64.exe');
if(Process.id!==SNAPSHOT.pid || mod.path.toLowerCase()!==PROFILE.image.toLowerCase())throw Error('Selected game image changed');
const base=mod.base;
const component=name=>SNAPSHOT.components.find(x=>x.name===name);
const fsd=ptr(component('fsd').address),life=ptr(component('fsd').lifecycle);
const pose=ptr(SNAPSHOT.poseLookup.poseAddress);
const bodies=ptr(SNAPSHOT.fsdSources.find(x=>x.name==='spaceBodies').address);
const navigation=ptr(SNAPSHOT.fsdSources.find(x=>x.name==='navigationTarget').address);
const same=()=>Process.getCurrentThreadId()===THREAD&&life.add(0xC0).readU32()===8&&life.add(0xB0).readU64().toString()===SNAPSHOT.player.entityId&&fsd.add(0x6A0).readPointer().equals(bodies)&&fsd.add(0x320).readPointer().equals(pose);
const hex=(at,n)=>Array.from(new Uint8Array(at.readByteArray(n))).map(x=>x.toString(16).padStart(2,'0')).join('');
const method=(obj,off)=>obj.readPointer().add(off).readPointer();
const rva=p=>p.sub(base).toString();
if(!method(pose,0x60).equals(base.add(0x2D9C2C0))||!method(bodies,0x60).equals(base.add(0x3CEB400))||!method(bodies,0xD0).equals(base.add(0x3CF04B0))||!method(navigation,0xB8).equals(base.add(0x2EC8E20)))throw Error('Pinned original getter bindings changed');
const radiusOut=Memory.alloc(16);
const radiusGetter=new NativeFunction(base.add(0x3CF04B0),'pointer',['pointer','pointer','pointer']);
const targetGetter=new NativeFunction(base.add(0x2EC8E20),'pointer',['pointer']);
const finite=x=>Number.isFinite(x)&&Math.abs(x)<1e30;
let last=0,queries=0;
Interceptor.attach(base.add(0x3CEB400),{
onEnter(args){
this.selected=false;
try{
if(!args[0].equals(bodies)||!same())return;
queries++;
if(Date.now()-last<200)return;
this.out=args[1];this.address=args[2].readU64().toString();this.selected=true;
}catch(e){send({kind:'error',stage:'enter',error:String(e)});}
},
onLeave(ret){
if(!this.selected)return;
try{
if(!same())return;
const body=this.out.readPointer();if(body.isNull())return;
const kind=body.add(0x20).readU32();if(![1,2,7].includes(kind))return;
// The original caller still owns this returned body reference. Do not retain or release it.
const result=radiusGetter(bodies,radiusOut,body);if(!result.equals(radiusOut))throw Error('Radius getter returned an unexpected buffer');
const radius=radiusOut.readDouble(),settings=fsd.add(0x50).readPointer();
const multiplier=settings.add(0x44).readFloat();
if(!finite(radius)||radius<=0||!finite(multiplier)||multiplier<=0)throw Error('Invalid radius/settings');
const target=targetGetter(navigation);
const row={kind:'body-query',utcMilliseconds:Date.now(),thread:Process.getCurrentThreadId(),queries,queryUniversalAddress:this.address,
body:body.toString(),bodyKind:kind,bodyTableRva:rva(body.readPointer()),radius,escapeRadiusMultiplier:multiplier,
worldUniversalAddress:hex(pose.add(0xE8),160),worldAddress:pose.add(0xE8).readU64().toString(),
fsdStage:fsd.add(0x794).readU8(),selectedTarget:target.isNull()?null:hex(target,224),bodyHeader:hex(body,0x480)};
last=Date.now();send(row);
}catch(e){send({kind:'error',stage:'leave',error:String(e)});}
}
});
send({kind:'ready',pid:Process.id,thread:THREAD,readOnly:true,screenUse:false});