using System.Text.Json; using System.Text.Json.Nodes; namespace XFEEDToolBox.Plugin; internal static unsafe partial class Navigation { [UnmanagedCallersOnly] static ulong InterfaceMenuOriginal(nuint activity,float dt)=>activity==321&&dt==.25f?0xFEDCBA9876543210UL:0; // Called only through the standalone diagnostic export. No game calls, hooks or input. internal static uint InterfaceProtocolSelfTest() { static JsonElement Request(string text){using var document=JsonDocument.Parse(text);return document.RootElement.Clone();} static JsonElement RoundTrip(JsonNode value)=>Request(value.ToJsonString()); static bool Rejected(Action operation){try{operation();return false;}catch{return true;}} uint passed=0; lock(galaxyMutex) { var saved=galaxyWork;var savedGeneration=galaxyGeneration; try { galaxyWork=new(){generation=61,done=true,items=[ new(){id=9007199254740995,position=[1.25,-2,3],starClass=4,name="阿尔法 🚀"}, new(){id=42,position=[4,5,6],starClass=uint.MaxValue,name="Second"}]}; var first=RoundTrip(GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":61}"))); if(first.GetProperty("total").GetInt32()==2&&first.GetProperty("items")[0].GetProperty("name").GetString()=="阿尔法 🚀"&& first.GetProperty("items")[0].GetProperty("systemAddress").ValueKind==JsonValueKind.String&&first.GetProperty("items")[0].GetProperty("systemAddress").GetString()=="9007199254740995")passed|=1; var page=RoundTrip(GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":61,\"offset\":1,\"limit\":96}"))); if(page.GetProperty("items").GetArrayLength()==1&&page.GetProperty("items")[0].GetProperty("name").GetString()=="Second"&&page.GetProperty("items")[0].GetProperty("starClass").GetString()=="Unknown")passed|=2; var empty=RoundTrip(GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":61,\"limit\":0}"))); var pastEnd=RoundTrip(GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":61,\"offset\":18446744073709551615}"))); if(empty.GetProperty("items").GetArrayLength()==0&&empty.GetProperty("total").GetInt32()==2&&pastEnd.GetProperty("items").GetArrayLength()==0)passed|=4; if(Rejected(()=>GalaxyCatalogueRequest("galaxy.lookup",Request("{\"query\":\"\"}")))&& Rejected(()=>GalaxyCatalogueRequest("galaxy.lookup",Request("{\"query\":\"x\\u0000y\"}")))&& Rejected(()=>GalaxyCatalogueRequest("galaxy.lookup",Request("{\"query\":\""+new string('星',43)+"\"}")))&& Rejected(()=>GalaxyCatalogueRequest("galaxy.result",Request("{\"generation\":60}"))))passed|=8; galaxyGeneration=61; var lookup=RoundTrip(GalaxyCatalogueRequest("galaxy.lookup",Request("{\"query\":\"阿尔法\"}"))); if(lookup.GetProperty("generation").GetUInt64()==62&&!lookup.GetProperty("done").GetBoolean()&&galaxyWork.query=="阿尔法"&& Rejected(()=>GalaxyCatalogueRequest("galaxy.suggest",Request("{\"query\":\"Sol\"}"))))passed|=16; galaxyWork.done=true; if(Rejected(()=>GalaxyCatalogueRequest("galaxy.region",Request("{\"centre\":[0,0],\"radius\":5}")))&& Rejected(()=>GalaxyCatalogueRequest("galaxy.region",Request("{\"centre\":[0,0,0],\"radius\":0.01}")))&& Rejected(()=>GalaxyCatalogueRequest("galaxy.region",Request("{\"centre\":[0,0,0],\"radius\":701}")))&& Rejected(()=>GalaxyCatalogueRequest("galaxy.region",Request("{\"centre\":[200001,0,0],\"radius\":5}")))) { var region=RoundTrip(GalaxyCatalogueRequest("galaxy.region",Request("{\"centre\":[1,-2,3],\"radius\":700}"))); if(region.GetProperty("generation").GetUInt64()==63&&galaxyWork.region&&galaxyWork.radius==700&&galaxyWork.centre[1]==-2)passed|=32; } } finally{galaxyWork=saved;galaxyGeneration=savedGeneration;} } lock(sessionMenuLock) { var saved=sessionMenuFrame;var savedWork=sessionMenuWork; try { var now=GetTickCount64(); sessionMenuFrame=new(){sequence=71,tick=now,menuTick=now,utc=UtcMilliseconds(),state="MainMenu",next="MainMenu",menuState="MainMenu",valid=true,count=2, items=[new(){name="ContinueMenu",enabled=true},new(){name="DisabledMenu",enabled=false}]}; sessionMenuWork=new(){id=new string('a',32),applied=true}; var menu=RoundTrip(SessionMenuDescription()); if(menu.GetProperty("sequence").GetUInt64()==71&&menu.GetProperty("state").GetString()=="MainMenu"&&menu.GetProperty("actions").GetArrayLength()==2&& menu.GetProperty("actions")[0].GetProperty("enabled").GetBoolean()&&!menu.GetProperty("actions")[1].GetProperty("enabled").GetBoolean()&& menu.GetProperty("lastRequestId").GetString()==new string('a',32)&&menu.GetProperty("actionApplied").GetBoolean())passed|=64; sessionMenuFrame.tick=now-301;sessionMenuWork.pending=true;sessionMenuWork.expires=now; var expired=RoundTrip(SessionMenuDescription()); if(expired.GetProperty("state").GetString()==""&&expired.GetProperty("actions").GetArrayLength()==0&&expired.GetProperty("actionFailed").GetBoolean())passed|=128; } finally{sessionMenuFrame=saved;sessionMenuWork=savedWork;} } if(SkyCapture.LayoutSelfTest())passed|=256; if(SessionOwnerId(new string('a',32))&&!SessionOwnerId(new string('A',32))&&!SessionOwnerId(new string('a',31))&& SessionActionAllowed("MainMenu","ContinueMenu")&&SessionActionAllowed("ContinueMenu","SetupPlayWithEveryone")&& !SessionActionAllowed("Pause","ExitToDesktop")&&!SessionActionAllowed("Pause","Cancel Quit To Main Menu")&& SessionActionAllowed("Pause","Confirmed Quit To Main Menu"))passed|=512; var numbers=RoundTrip(JsonWire.Obj(("finite",3d),("nan",double.NaN),("infinity",double.PositiveInfinity),("negativeInfinity",float.NegativeInfinity), ("unknown",null),("array",JsonWire.Arr(float.NaN,double.NegativeInfinity,1d)))); if(numbers.GetProperty("finite").GetDouble()==3&&numbers.GetProperty("nan").ValueKind==JsonValueKind.Null&& numbers.GetProperty("infinity").ValueKind==JsonValueKind.Null&&numbers.GetProperty("negativeInfinity").ValueKind==JsonValueKind.Null&& numbers.GetProperty("unknown").ValueKind==JsonValueKind.Null&&numbers.GetProperty("array")[0].ValueKind==JsonValueKind.Null&& numbers.GetProperty("array")[1].ValueKind==JsonValueKind.Null&&numbers.GetProperty("array")[2].GetDouble()==1)passed|=1024; lock(initializeMutex) { var savedMenu=originalSessionMenuUpdate;var savedPause=originalSessionPauseUpdate;var savedEnabled=enabledProvider;var savedActive=active;var savedInitialized=initialized; try { originalSessionMenuUpdate=originalSessionPauseUpdate=(nuint)(delegate* unmanaged)&InterfaceMenuOriginal; active=initialized=true;enabledProvider=()=>throw new InvalidOperationException("Synthetic observation failure"); var menu=(nuint)(delegate* unmanaged)&SessionMenuUpdateHook; var pause=(nuint)(delegate* unmanaged)&SessionPauseUpdateHook; if(Call(menu,321,F32(.25f))==0xFEDCBA9876543210UL&&Call(pause,321,F32(.25f))==0xFEDCBA9876543210UL)passed|=2048; } finally{originalSessionMenuUpdate=savedMenu;originalSessionPauseUpdate=savedPause;enabledProvider=savedEnabled;active=savedActive;initialized=savedInitialized;} } return passed; } }