using System.Diagnostics; using System.Text.Json; using XFEEDToolBox.Core.Data; using XFEEDToolBox.Core.Models; using XFEEDToolBox.Core.Navigation; // Reads the real native endpoint and evaluates decisions without applying them. internal static class NativeReadAcceptance { public static async Task RunAsync(int pid,string reportPath) { if(File.Exists(reportPath))throw new IOException("Use a new native read acceptance report."); const string hash=XFEEDToolBox.Core.Native.NativeSystemLocationReader.GameSha256; using var process=Process.GetProcessById(pid);var processStart=process.StartTime; var directory=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),"Saved Games","Frontier Developments","Elite Dangerous"); await using var journal=new JournalMonitor(directory);await journal.StartAsync();var before=journal.State.Navigation; var pipe=new NavigationPipeClient(pid);var hello=await pipe.CallAsync(new{op="describe"}); if(hello.GetProperty("processId").GetInt32()!=pid||hello.GetProperty("gameSha256").GetString()!=hash||!hello.GetProperty("referenceGeometry").GetBoolean())throw new InvalidDataException("The repaired native reader is not loaded in the selected game."); var projector=new NativeFrameProjector(hash);var navigator=new FlightNavigator(); Vector3d? initialPosition=null;double movement=0,peak=0;var frames=0;var eligible=0;var bodyCount=0; var watch=Stopwatch.StartNew();FlightObservation? last=null;FlightDecision? decision=null;NavWaypoint? next=null; var current=before.CurrentSystemAddress;var lastJump=before.LastJumpAt; while(watch.Elapsedw.SystemAddress==target)??throw new InvalidDataException("Actual locked target is missing from the actual game route."); last=projector.Project(raw,journal.State,next,.5,DateTimeOffset.UtcNow); if(last.Frame.SystemAddress!=current||journal.State.Navigation.CurrentSystemAddress!=current||journal.State.Navigation.LastJumpAt!=lastJump)throw new InvalidDataException("Read acceptance changed system or observed an unexpected jump."); decision=navigator.Decide(last.Frame,next,last.Thermal,DateTimeOffset.UtcNow); if(decision.BeginCharging&&decision.Throttle==1)eligible++; bodyCount=raw.GetProperty("geometry").GetProperty("nearbyBodies").GetArrayLength(); peak=Math.Max(peak,last.Frame.HeatPercent??0);frames++; await Task.Delay(40); } var passed=frames>=20&&eligible>0&&movement<1&&!process.HasExited&&process.StartTime==processStart; await File.WriteAllTextAsync(reportPath,JsonSerializer.Serialize(new{processId=pid,version=hello.GetProperty("version").GetString(),frames,eligibleReadFrames=eligible, currentSystem=journal.State.SystemName,currentSystemAddress=current,next=next?.Name,localMovementMetres=movement,bodyCount,peakHeat=peak, lastFrame=last?.Frame,decisionPreviewOnly=decision,passed,flightCommandsInvoked=false,fsdInputPulses=0,targetSelectionInvoked=false, screenUse=false,journalWrites=0,gameNativeCallsInvoked=false},new JsonSerializerOptions{WriteIndented=true})); Console.WriteLine(JsonSerializer.Serialize(new{passed,frames,eligible,bodyCount,localMovementMetres=movement,next=next?.Name,flightCommandsInvoked=false})); if(!passed)throw new InvalidOperationException("Native read acceptance did not satisfy all idle-position and readiness checks."); } }